Utilisez Shifter avec Selenium
Connectez les proxies résidentiels et ISP de Shifter à Selenium WebDriver en Python, Java, JavaScript, C# et Ruby. Compatible avec Chrome, Firefox et Edge — associez à selenium-wire pour une authentification complète par nom d'utilisateur et mot de passe en mode headless.
Démarrage rapide
Installer
pip install selenium selenium-wire Utilisation de base
# 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() Fonctionnalités
Exemples
Python + selenium-wire (Session persistante)
selenium-wire achemine le trafic via un MITM en cours de processus, ce qui signifie que les proxies avec nom d'utilisateur et mot de passe fonctionnent simplement en mode headless Chrome. Ajoutez un `sid` pour une IP résidentielle persistante sur toute la session.
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 classique (sans extras) — Liste blanche d'IP
Si vous ne souhaitez pas selenium-wire comme dépendance, utilisez l'authentification par liste blanche d'IP de Shifter et configurez le proxy via les ChromeOptions standard. Des dépendances plus légères, mais vous devez mettre en liste blanche votre hôte de scraping.
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 avec l'équivalent de selenium-wire (BrowserMob)
Java ne dispose pas de selenium-wire, mais BrowserMob Proxy remplit le même rôle — démarrez un proxy local qui ajoute des en-têtes d'authentification basique, puis pointez Selenium vers celui-ci.
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 (navigateurs en parallèle)
Lorsque vous passez à un hub Grid avec plusieurs nœuds, configurez Shifter une seule fois au niveau des Capabilities — chaque nœud acheminera le trafic via Shifter sans configuration par nœud.
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() Questions fréquentes Questions FAQ
Questions fréquentes sur l'utilisation de Shifter avec Selenium.
Utilisez selenium-wire (Python) ou BrowserMob Proxy (Java). Les deux exécutent un proxy MITM local qui injecte des en-têtes d'authentification basique — Chrome et Firefox acceptent le proxy interne sans demander d'identifiants, même en mode headless. Vous pouvez également utiliser l'authentification par liste blanche d'IP de Shifter et ignorer les identifiants.
Commencer à utiliser Shifter avec Selenium
Pilotez Selenium WebDriver via les proxies résidentiels et ISP 205M+ de Shifter en Python, Java et bien d'autres langages. Indicateur natif --proxy-server, selenium-wire pour l'authentification headless, et prise en charge complète de Selenium Grid.