如何将代理 IP 用于 selenium chrome?
我已经复制了 steps in this question和 this question但无法让 chrome 使用新代理。
要复制,请从 this site 中选择任何免费 IP然后执行:
PROXY = "80.237.6.1:34880"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)
chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("https://www.whatismyip.com/my-ip-information/")
chrome打开wahtismyip.com页面时,显示的IP是我自己的,不是代理。
请您参考如下方法:
您必须设置功能并强制其使用手动代理。 用户名和密码是可选的。 PROXY 的格式应为 ' http://68.251.250.193:8080 '
proxy = {'address': PROXY,
'username': 'USERNAME',
'password': 'PASSWORD'}
capabilities = dict()
capabilities['proxy'] = {'proxyType': 'MANUAL',
'httpProxy': proxy['address'],
'ftpProxy': proxy['address'],
'sslProxy': proxy['address'],
'noProxy': '',
'class': "org.openqa.selenium.Proxy",
'autodetect': False,
'socksUsername': proxy['username'],
'socksPassword': proxy['password']}
chrome = webdriver.Chrome(executable_path = 'C:\\Users\\whereveryourpathtochromedriveris',
chrome_options=chrome_options,
desired_capabilities=capabilities)
chrome.get("https://www.whatismyip.com/my-ip-information/")
