Selenium과 XProxy 연동
Python Selenium 및 Chrome Driver 웹 자동화를 XProxy 4G/5G 모바일 프록시를 통해 라우팅하고 자동 IP 로테이션 트리거를 사용하는 방법을 배웁니다.
XProxy를 Selenium과 함께 사용하는 이유
Selenium은 웹 스크래핑, 브라우저 자동화, 봇 개발의 업계 표준 프레임워크입니다. Selenium 스크레이퍼를 XProxy 자체 호스팅 4G/5G 모바일 프록시로 라우팅하면 실제 모바일 통신사 IP를 필요할 때 로테이션하여 Cloudflare 안티봇 검사, IP 속도 제한, CAPTCHA를 우회할 수 있습니다.
사전 요구 사항
selenium패키지가 설치된 Python 3.8+(pip install selenium requests).- 활성 4G/5G USB 동글 또는 Android 폰이 있는 XProxy 서버 실행 중.
- XProxy 대시보드의 프록시 SOCKS5/HTTP 자격 증명과 로테이션 API 링크.
Python Selenium 코드 예제
XProxy HTTP/SOCKS5 프록시로 Selenium Chrome Driver를 구성하고 스크래핑 작업을 시작하기 전에 IP 로테이션을 트리거하는 프로덕션 준비 완료 Python 스크립트:
selenium_xproxy_example.py
import time
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# --- XProxy Configuration ---
XPROXY_HOST = "192.168.6.7" # Your XProxy server IP
XPROXY_PORT = 5001 # Port assigned to dongle #1 (HTTP/SOCKS5)
ROTATION_API_URL = "http://192.168.6.7:8081/api/v1/rotate_ip/position/1"
def rotate_xproxy_ip():
"""Trigger 4G/5G cellular reconnect on XProxy modem."""
print("🔄 Requesting XProxy IP rotation...")
try:
res = requests.get(ROTATION_API_URL, timeout=10)
if res.status_code == 200:
print("✅ IP rotation triggered successfully. Waiting 5s for cellular reconnect...")
time.sleep(5)
return True
else:
print(f"⚠️ Failed to rotate IP: HTTP {res.status_code}")
except Exception as e:
print(f"❌ Error calling XProxy Rotation API: {e}")
return False
def run_selenium_scraper():
# 1. Rotate IP before launch
rotate_xproxy_ip()
# 2. Configure Chrome Driver Proxy Options
chrome_options = Options()
chrome_options.add_argument(f'--proxy-server=http://{XPROXY_HOST}:{XPROXY_PORT}')
chrome_options.add_argument('--headless') # Run headless if desired
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)
try:
# 3. Verify exit IP address
print("🌐 Checking exit IP via Selenium...")
driver.get("https://api.ipify.org?format=json")
print("Response body:", driver.page_source)
# 4. Perform your scraping tasks...
driver.get("https://httpbin.org/ip")
print("Page Title:", driver.title)
finally:
driver.quit()
if __name__ == "__main__":
run_selenium_scraper()Selenium에서 인증 프록시 처리
XProxy 채널에 인증(사용자 이름 & 비밀번호)이 활성화되어 있으면 selenium-wire 또는 proxy-chrome-extension과 같은 가벼운 확장 프로그램으로 자격 증명을 원활하게 제공하세요:
selenium_wire_auth.py
from seleniumwire import webdriver
seleniumwire_options = {
'proxy': {
'http': 'http://username:[email protected]:5001',
'https': 'https://username:[email protected]:5001',
'no_proxy': 'localhost,127.0.0.1'
}
}
driver = webdriver.Chrome(seleniumwire_options=seleniumwire_options)
driver.get("https://httpbin.org/ip")
print(driver.page_source)Why High-Quality SOCKS5 UDP & Mobile Proxies Matter for Selenium
Using cheap datacenter proxies or basic HTTP proxies in antidetect profiles leads to instant account suspensions on Facebook, Google, TikTok, and Amazon. Here is why XProxy's self-hosted 4G/5G mobile proxies deliver superior anonymity and trust:
- SOCKS5 with Full UDP Support: Unlike standard HTTP proxies that drop UDP packets, XProxy SOCKS5 proxies fully support UDP datagrams. This ensures WebRTC, DNS queries, and real-time audio/video sockets route securely through your proxy without revealing your real IP address.
- Instant REST API IP Rotation: Trigger cellular IP rotation on demand via simple HTTP GET requests (e.g.
http://192.168.6.7:8081/api/v1/rotate_ip/position/1). Reconnect 4G/5G USB modems in 3 to 8 seconds with zero proxy dropouts. - 100% WebRTC & DNS Leak Protection: Combined with XProxy's local LAN gateway and TCP OS Spoofing, your browser profiles maintain pristine anonymity scores on BrowserLeaks, Whoer, Pixelscan, and IPhey.
- Carrier-Grade NAT (CGNAT) Trust: Mobile carrier IPs are shared by thousands of active smartphone users. Major platforms never ban mobile IP ranges, granting your accounts maximum trust.
Was this page helpful?
