如何将代理IP与硒铬一起使用?
我已经复制了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/")
关于python - 用 Selenium Chrome 设置代理地址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53066926/