Use a Shifter com Selenium
Conecte os proxies residenciais e ISP da Shifter ao Selenium WebDriver em Python, Java, JavaScript, C# e Ruby. Funciona com Chrome, Firefox e Edge, combine com selenium-wire para autenticação completa de usuário e senha no modo headless.
Início 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() Recursos
Exemplos
Python + selenium-wire (Sessão Persistente)
O selenium-wire encaminha o tráfego por meio de um MITM em processo, o que significa que proxies com usuário e senha simplesmente funcionam no Chrome headless. Adicione um `sid` para um IP residencial sticky em toda a sessão.
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 puro (sem extras) — Lista Branca de IP
Se você não quer o selenium-wire como dependência, use a autenticação por whitelist de IP do Shifter e configure o proxy via ChromeOptions padrão. Dependências mais limpas, mas você precisa colocar seu host de scraping na whitelist.
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 com equivalente ao selenium-wire (BrowserMob)
O Java não tem selenium-wire, mas o BrowserMob Proxy cumpre a mesma função: inicie um proxy local que adiciona cabeçalhos de autenticação Basic, depois direcione o Selenium para ele.
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 paralelos)
Quando você escala para um hub Grid com vários nós, configure o Shifter uma vez no nível de Capabilities; todos os nós serão roteados pelo Shifter sem necessidade de configuração por nó.
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() Perguntas frequentes
Perguntas comuns sobre usar o Shifter com Selenium.
Use selenium-wire (Python) ou BrowserMob Proxy (Java). Ambos executam um proxy MITM local que injeta cabeçalhos de autenticação Basic - o Chrome e o Firefox aceitam o proxy interno sem solicitar credenciais, mesmo no modo headless. Como alternativa, use a autenticação por lista de permissões de IP da Shifter e dispense totalmente as credenciais.
O Chrome não exibe diálogos de autenticação de proxy no modo headless e não há uma forma nativa de fornecer credenciais na linha de comando. O selenium-wire contorna isso executando um proxy local que lida com a autenticação. A outra opção é o modo de whitelist de IP do Shifter — o IP de saída do seu host de scraping é pré-autorizado, então nenhuma credencial é necessária.
Pass --proxy-server=http://p.shifter.io:443 in ChromeOptions. For username-password auth in headless mode, use selenium-wire (Python) or BrowserMob (Java). For visible Chrome, page.authenticate() in the underlying CDP works, but most scrapers use selenium-wire as the cleanest option.
Adicione um ID de sessão ao nome de usuário do proxy, por exemplo, `customer-USERNAME-country-us-sid-123ABC`. Toda requisição através da mesma sessão WebDriver reutilizará o mesmo IP residencial. Adicione `ttl-N` para fixar o IP por até N segundos.
Sim. Configure o proxy no nível de Capabilities ou ChromeOptions ao criar o Remote WebDriver — todos os nós do Grid serão roteados pelo Shifter. Combine com sids exclusivos por worker para escalar o scraping paralelo sem compartilhar IPs.
Se você está começando do zero, o Playwright costuma ser mais fácil — a autenticação de proxy funciona nativamente, o suporte a múltiplos navegadores já vem incluso, e a API é mais limpa. O Selenium continua sendo a escolha certa para suítes de teste legadas, mobile (Appium), ou quando sua equipe já padroniza nele. O Shifter funciona igualmente bem com ambos.
Comece a Usar o Shifter com Selenium
Execute o Selenium WebDriver através dos 205M+ proxies residenciais e de ISP do Shifter em Python, Java e outras linguagens. Flag nativa --proxy-server, selenium-wire para autenticação headless e suporte completo ao Selenium Grid.