如何在 selenium python 中实现 TOR socks 代理?

问题描述 投票:0回答:0

我能够通过简单的请求会话使用 socks 代理获得不同的 IP 地址。

def check_ip():
    session = requests.session()
    creds = str(random.randint(10000,0x7fffffff)) + ":" + "password"
    session.proxies = {'http': 'socks5h://{}@localhost:9050'.format(creds), 'https': 'socks5h://{}@localhost:9050'.format(creds)}
    r = session.get('http://httpbin.org/ip')
    print("response text:", r.text)

# Just to validate it really is working
for i in range(9):
    check_ip()

但是,我应该如何使用 chromedriver 在 selenium 中实现 socks 代理。我应该设置什么样的参数。我想确保每个实例的 IP 地址都不同,以防止 recaptcha 检测到异常活动(我试图用 selenium 解决 recaptcha)。顺便说一下,我在 Windows 上。

如有任何帮助,我们将不胜感激。

python selenium-webdriver
© www.soinside.com 2019 - 2024. All rights reserved.