webdriver+Chrome 設定代理
阿新 • • 發佈:2018-12-06
from selenium import webdriver chromeOptions = webdriver.ChromeOptions() # 設定代理 chromeOptions.add_argument("--proxy-server=http://202.20.16.82:10152") # 一定要注意,=兩邊不能有空格,不能是這樣--proxy-server = http://202.20.16.82:10152 browser = webdriver.Chrome(chrome_options = chromeOptions) # 檢視本機資訊,檢視代理是否起作用 browser.get("http://httpbin.org/get")
結果如下
{ "args": {}, "headers": { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "close", "Host": "httpbin.org", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.3319.102 Safari/537.36", "X-Via": "Cache-389" }, "origin": "117.191.11.112", "url": "http://httpbin.org/get" }