webdriver添加正确ip代理依然访问失败的坑
import requests from selenium import webdriver url="https://www.baidu.com/" ip="114.96.199.198" port = "4325" proxy={"http":"http://"+ip+":"+port} headers={"User-Agent":"Mozilla/5.0"} res=requests.get(url,proxies=proxy,headers=headers) print(res.status_code) # 返回200:表示该ip代理是可用的 print('------------------') chrome_path = '/Users/dannihong/downloads/webdriver_browser/chromedriver86' options=webdriver.ChromeOptions() options.add_argument('--proxy-server=http://'+ip+":"+port) options.add_argument('--proxy-server=http://114.96.199.198:4325') # 必须是中文冒号 driver=webdriver.Chrome(executable_path=chrome_path, chrome_options=options) driver.get(url)
options.add_argument()里的参数端口冒号,改为中文的冒号,一下子就访问成功了。