[英]Using Selenium to run webdriver (Chrome) and setting up proxy to log browsed URL
[英]Problems with setting up proxy for chrome using selenium 3.8.1
我曾經像下面的代碼一樣在 chrome 上設置代理,但是當我更新到 selenium 3.8.1 代理停止工作時,我沒有收到任何錯誤,它只是不使用代理服務器,我不知道為什么。 我的 chromedriver 也是最新的。
options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=192.99.55.120:3128')
driver = webdriver.Chrome(executable_path='C:\chromedriver_win32\chromedriver.exe', chrome_options=options)
driver.get("http://google.com/")
想收到任何建議,也許是為 chromedriver 設置代理的替代方法。
試試
options.add_argument('--proxy-server="http=192.99.55.120:3128;https=192.99.55.120:3128"')
還嘗試使用這些參數直接運行您的 chrome 二進制文件,看看它是否有效
chrome.exe --proxy-server="http=192.99.55.120:3128"
如果有人仍然感興趣,這就是我最終解決問題的方法
from selenium.webdriver import Proxy
settings = {
"httpProxy": "192.99.55.120:3128",
"sslProxy": "192.99.55.120:3128"
}
proxy = Proxy(settings)
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME.copy()
cap['platform'] = "WINDOWS"
cap['version'] = "10"
proxy.add_to_capabilities(cap)
from selenium.webdriver.chrome.webdriver import WebDriver as ChromeDriver
driver = ChromeDriver(desired_capabilities=cap, executable_path='C:\chromedriver_win32\chromedriver.exe')
如果導航器要求提供代理的憑據用戶名和密碼,並且您需要處理此問題:(僅當出現警報時)
driver.get("http://username:password@google.com/")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.