Intégration avec Selenium

Découvrez comment acheminer l'automatisation web Python Selenium et Chrome Driver via les proxys mobiles 4G/5G XProxy, avec des déclencheurs de rotation d'IP automatisés.

Pourquoi utiliser XProxy avec Selenium ?

Selenium est le framework de référence du secteur pour le web scraping, l'automatisation de navigateur et le développement de bots. En acheminant vos scrapers Selenium à travers les proxys mobiles 4G/5G auto-hébergés de XProxy, vous contournez les contrôles anti-bot de Cloudflare, les limites de débit par IP et les CAPTCHA en faisant tourner à la demande de véritables adresses IP d'opérateurs mobiles.

Prérequis

  • Python 3.8+ avec le package selenium installé (pip install selenium requests).
  • Un serveur XProxy en cours d'exécution avec des dongles USB 4G/5G actifs ou des téléphones Android.
  • Les identifiants du proxy SOCKS5 ou HTTP et le lien de l'API de rotation depuis le tableau de bord XProxy.

Exemple de code Python Selenium

Voici un script Python prêt pour la production qui configure Selenium Chrome Driver avec un proxy HTTP/SOCKS5 XProxy et déclenche la rotation d'IP avant de lancer une tâche de scraping :

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()

Gérer les proxys authentifiés dans Selenium

Si l'authentification est activée sur votre canal XProxy (nom d'utilisateur & mot de passe), utilisez selenium-wire ou une extension légère telle que proxy-chrome-extension pour fournir les identifiants de manière transparente :

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)
driver.quit()

Why High-Quality SOCKS5 UDP & Mobile Proxies Matter for Selenium & Web Automation

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.
🚀 Build Your Own 4G/5G Proxy Farm

Stop Paying Monthly Rented Proxy Fees

XProxy hardware & software lets you own private mobile proxy channels with unlimited data, zero bandwidth caps, SOCKS5 UDP support, and instant REST API IP rotation (Selenium Automation).

XProxy XH22 4G 5G Mobile Proxy Hardware Kit