Shifter와 함께 사용 Selenium
Shifter의 레지덴셜 및 ISP 프록시를 Python, Java, JavaScript, C#, Ruby 전반의 Selenium WebDriver에 연결하세요. Chrome, Firefox, Edge와 함께 작동하며, 헤드리스 모드에서 완전한 사용자명-비밀번호 인증을 위해 selenium-wire와 함께 사용하세요.
빠른 시작
설치
pip install selenium selenium-wire 기본 사용법
# 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() 기능
예시
Python + selenium-wire (Sticky Session)
selenium-wire는 인프로세스 MITM을 통해 트래픽을 전달하므로, 사용자 이름/비밀번호 프록시가 헤드리스 Chrome에서 바로 작동합니다. 전체 세션 동안 고정된 레지덴셜 IP를 사용하려면 `sid`를 추가하세요.
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() Vanilla Selenium (추가 기능 없음) — IP 화이트리스트
selenium-wire를 종속성으로 두고 싶지 않다면 Shifter의 IP 화이트리스트 인증을 사용하고 표준 ChromeOptions를 통해 프록시를 설정하세요. 더 깔끔한 종속성이지만 스크래핑 호스트를 화이트리스트에 등록해야 합니다.
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와 selenium-wire와 동등한 도구(BrowserMob)
Java에는 selenium-wire가 없지만, BrowserMob Proxy가 동일한 역할을 합니다. 로컬 프록시를 시작하여 Basic 인증 헤더를 추가한 다음 Selenium을 이 프록시로 연결하세요.
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 (병렬 브라우저)
여러 노드가 있는 Grid 허브로 확장할 때는 Capabilities 레벨에서 Shifter를 한 번만 구성하면, 노드별 설정 없이 모든 노드가 Shifter를 통해 라우팅됩니다.
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() 자주 묻는 질문
Selenium와 Shifter 사용에 관한 일반적인 질문.
selenium-wire(Python) 또는 BrowserMob Proxy(Java)를 사용하세요. 둘 다 로컬 MITM 프록시를 실행하여 Basic 인증 헤더를 삽입합니다. Chrome과 Firefox는 헤드리스 모드에서도 자격 증명을 요청하지 않고 내부 프록시를 수락합니다. 또는 Shifter의 IP 화이트리스트 인증을 사용하여 자격 증명을 아예 생략할 수도 있습니다.
Chrome은 헤드리스 모드에서 프록시 인증 대화 상자를 표시하지 않으며 명령줄에서 자격 증명을 제공하는 내장 방법이 없습니다. selenium-wire는 인증을 자체적으로 처리하는 로컬 프록시를 실행하여 이를 우회합니다. 다른 방법은 Shifter의 IP 화이트리스트 모드입니다 — 스크레이핑 호스트의 아웃바운드 IP가 사전 승인되어 있어 자격 증명이 필요하지 않습니다.
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.
프록시 사용자 이름에 세션 ID를 추가하세요(예: `customer-USERNAME-country-us-sid-123ABC`). 동일한 WebDriver 세션을 통한 모든 요청은 동일한 레지덴셜 IP를 재사용합니다. `ttl-N`을 추가하면 해당 IP를 최대 N초 동안 고정할 수 있습니다.
예. Remote WebDriver를 생성할 때 Capabilities 또는 ChromeOptions 수준에서 프록시를 구성하세요. 모든 Grid 노드가 Shifter를 통해 라우팅됩니다. 워커마다 고유한 sid를 결합하면 IP를 공유하지 않고도 병렬 스크래핑을 확장할 수 있습니다.
처음 시작하는 경우 Playwright가 대개 더 쉽습니다. 프록시 인증이 네이티브로 작동하고, 멀티 브라우저 지원이 내장되어 있으며, API가 더 깔끔합니다. Selenium은 레거시 테스트 스위트, 모바일(Appium), 또는 팀이 이미 표준화한 경우에 여전히 올바른 선택입니다. Shifter는 두 가지 모두와 동등하게 잘 작동합니다.
Shifter 사용을 함께 시작하기 Selenium
Shifter의 205M+ 레지덴셜 및 ISP 프록시를 통해 Python, Java 등에서 Selenium WebDriver를 구동하세요. 네이티브 --proxy-server 플래그, 헤드리스 인증을 위한 selenium-wire, 완전한 Selenium Grid 지원을 제공합니다.