Usa Shifter con Selenium
Conecta los proxies residenciales e ISP de Shifter a Selenium WebDriver en Python, Java, JavaScript, C# y Ruby. Compatible con Chrome, Firefox y Edge; combínalo con selenium-wire para autenticación completa con usuario y contraseña en modo headless.
Inicio rápido
Instalar
pip install selenium selenium-wire Uso básico
# selenium-wire is a drop-in replacement for selenium that adds first-class
# support for authenticated proxies in headless mode.
from seleniumwire import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless=new")
seleniumwire_options = {
"proxy": {
"http": "customer-USERNAME-country-us-sid-123ABC:PASSWORD@p.shifter.io:443",
"https": "customer-USERNAME-country-us-sid-123ABC:PASSWORD@p.shifter.io:443",
"no_proxy": "localhost,127.0.0.1",
}
}
driver = webdriver.Chrome(
options=options,
seleniumwire_options=seleniumwire_options,
)
driver.get("https://ipinfo.io/json")
print(driver.find_element("tag name", "body").text)
# {"ip": "154.16.xxx.xxx", "city": "New York", "country": "US", ...}
driver.quit() Características
Ejemplos
Python + selenium-wire (sesión persistente)
selenium-wire enruta el tráfico a través de un MITM en proceso, lo que significa que los proxies con usuario y contraseña funcionan sin problemas en Chrome headless. Añade un `sid` para obtener una IP residencial fija durante toda la sesión.
from seleniumwire import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import secrets
sid = secrets.token_hex(4)
options = Options()
options.add_argument("--headless=new")
options.add_argument(
"--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
)
proxy_url = (
f"customer-USERNAME-country-uk-city-london-sid-{sid}-ttl-300:"
f"PASSWORD@p.shifter.io:443"
)
driver = webdriver.Chrome(
options=options,
seleniumwire_options={"proxy": {"http": proxy_url, "https": proxy_url}},
)
# Multi-step flow — same residential IP across every navigation.
driver.get("https://example.co.uk/login")
driver.find_element(By.ID, "email").send_keys("user@example.com")
driver.find_element(By.ID, "password").send_keys("secret")
driver.find_element(By.CSS_SELECTOR, "button[type=submit]").click()
WebDriverWait(driver, 10).until(EC.url_contains("/dashboard"))
rows = driver.find_elements(By.CSS_SELECTOR, ".order-row")
print(f"Found {len(rows)} orders on dashboard")
driver.quit() Selenium estándar (sin extras): autenticación por lista blanca de IPs
Si no quieres selenium-wire como dependencia, usa la autenticación por lista blanca de IPs de Shifter y configura el proxy mediante ChromeOptions estándar. Dependencias más limpias, pero debes añadir tu host de scraping a la lista blanca.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
options = Options()
options.add_argument("--headless=new")
options.add_argument("--proxy-server=http://p.shifter.io:443")
options.add_argument(
"--user-agent=Mozilla/5.0 (Macintosh) AppleWebKit/537.36"
)
# When using IP-whitelist auth, your scrape host's outbound IP is
# pre-authorized — no username/password needed in the URL.
driver = webdriver.Chrome(options=options)
driver.get("https://example.com")
print(driver.title)
products = driver.find_elements(By.CSS_SELECTOR, ".product")
for p in products[:5]:
title = p.find_element(By.CSS_SELECTOR, "h2").text
price = p.find_element(By.CSS_SELECTOR, ".price").text
print(title, price)
driver.quit() Java con equivalente a selenium-wire (BrowserMob)
Java no tiene selenium-wire, pero BrowserMob Proxy cumple la misma función: inicia un proxy local que añade cabeceras de autenticación básica y luego apunta Selenium hacia él.
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.net.InetSocketAddress;
public class SeleniumShifter {
public static void main(String[] args) {
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.setChainedProxy(new InetSocketAddress("p.shifter.io", 443));
proxy.chainedProxyAuthorization(
"customer-USERNAME-country-de-sid-456DEF", "PASSWORD",
net.lightbody.bmp.proxy.auth.AuthType.BASIC);
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
ChromeOptions options = new ChromeOptions();
options.setProxy(seleniumProxy);
options.addArguments("--headless=new");
WebDriver driver = new ChromeDriver(options);
try {
driver.get("https://example.de");
System.out.println(driver.getTitle());
} finally {
driver.quit();
proxy.stop();
}
}
} Selenium Grid (navegadores en paralelo)
Cuando escales a un hub de Grid con varios nodos, configura Shifter una sola vez a nivel de Capabilities: cada nodo enrutará a través de Shifter sin necesidad de configuración por nodo.
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.chrome.options import Options
# Use selenium-wire-equivalent or Shifter IP whitelist for auth.
proxy_str = "p.shifter.io:443"
shared_proxy = Proxy()
shared_proxy.proxy_type = ProxyType.MANUAL
shared_proxy.http_proxy = proxy_str
shared_proxy.ssl_proxy = proxy_str
options = Options()
options.proxy = shared_proxy
options.add_argument("--headless=new")
# Grid hub
HUB_URL = "http://selenium-hub.internal:4444/wd/hub"
driver = webdriver.Remote(command_executor=HUB_URL, options=options)
try:
driver.get("https://example.com")
print(driver.title, len(driver.page_source), "bytes")
finally:
driver.quit() Preguntas frecuentes
Preguntas frecuentes sobre el uso de Shifter con Selenium.
Usa selenium-wire (Python) o BrowserMob Proxy (Java). Ambos ejecutan un proxy MITM local que inyecta cabeceras de autenticación básica: Chrome y Firefox aceptan el proxy interno sin solicitar credenciales, incluso en modo headless. También puedes usar la autenticación por lista blanca de IPs de Shifter y prescindir de las credenciales por completo.
Empieza a usar Shifter con Selenium
Conecta Selenium WebDriver a través de los más de 205M+ proxies residenciales y de ISP de Shifter en Python, Java y otros lenguajes. Indicador nativo --proxy-server, selenium-wire para autenticación sin interfaz gráfica y compatibilidad total con Selenium Grid.