For the complete documentation index, see llms.txt. This page is also available as Markdown.

Selenium

Selenium 驱动真实浏览器,代理配置取决于具体驱动(Chrome / Firefox)。两种思路:

  1. 无认证 — Chrome 用 --proxy-server 参数、Firefox 用 profile,浏览器仍会弹凭证框。

  2. 带认证 — 临时生成扩展自动填代理凭证框,这是采集场景的标准做法

Chrome — 使用 Selenium-Wire 处理认证

最干净的方案是 selenium-wire,对 Selenium 做了透明代理认证封装:

pip install selenium-wire
from seleniumwire import webdriver

USER = "helo_s1a2b3c4d5e-type-res-region-us"
PASS = "PASSWORD"

options = {
    "proxy": {
        "http":  f"http://{USER}:{PASS}@gate.helodata.io:7777",
        "https": f"http://{USER}:{PASS}@gate.helodata.io:7777",
        "no_proxy": "localhost,127.0.0.1",
    }
}

driver = webdriver.Chrome(seleniumwire_options=options)
driver.get("https://ipv4.icanhazip.com")
print(driver.page_source)
driver.quit()

ISP 用 http://helo_s1a2b3c4d5e:PASSWORD@198.51.100.42:8000

Chrome — 不用 selenium-wire(即时生成扩展)

无法引入 selenium-wire 时(如企业限制),即时生成一个 manifest-v3 扩展:

Firefox

Firefox 通过 FirefoxProfile 直接配代理 + 凭证 helper。配合 selenium-wire 写法同 Chrome。

验证

常见陷阱

  • 原生代理认证弹框 阻塞 headless 运行,headless 场景必须用 selenium-wire 或扩展方案

  • WebRTC 泄露 — 加 --disable-features=WebRtcHideLocalIpsWithMdns,或通过 chrome_options 添加 --disable-webrtc(Brave/Vivaldi 参数)。

  • headless 下代理未生效 — 旧用 --headless,新版 Chrome 必须 --headless=new 扩展机制才生效。

最后更新于

这有帮助吗?