我已经做了很多搜索,但是有很多令人困惑的片段非常相似。
我尝试过使用DesiredCapabilities
, ChromeOptions
, Options
和一系列的参数,但没有任何效果:( 它无法设置代理。
例如 (ChromeOptions
)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy=https://' + proxy_ip_and_port)
chrome_options.add_argument('--proxy-auth=' + proxy_user_and_pass)
chrome_options.add_argument('--proxy-type=https')
browser = webdriver.Chrome("C:\drivers\chromedriver.exe")
另一个例子 (Options
)
options = Options()
options.add_argument('--proxy=https://' + proxy_ip_and_port)
options.add_argument('--proxy-auth=' + proxy_user_and_pass)
options.add_argument('--proxy-type=https')
browser = webdriver.Chrome("C:\drivers\chromedriver.exe", chrome_options=options)
我也用过--proxy-server
代替--proxy-auth
, --proxy-type
...等甚至格式为:'--proxy-server=http://' + proxy_user_and_pass + '@' + proxy_ip_and_port
另一个例子 (DesiredCapabilities
)
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = dict(DesiredCapabilities.CHROME)
capabilities['proxy'] = {'proxyType': 'MANUAL',
'httpProxy': proxy_ip_and_port,
'ftpProxy': proxy_ip_and_port,
'sslProxy': proxy_ip_and_port,
'noProxy': '',
'class': "org.openqa.selenium.Proxy",
'autodetect': False}
capabilities['proxy']['socksUsername'] = proxy_user
capabilities['proxy']['socksPassword'] = proxy_pass
browser = webdriver.Chrome(executable_path="C:\drivers\chromedriver.exe", desired_capabilities=capabilities)
我也在 Firefox 中尝试过,但发生了同样的问题,它使用具有我的正常 IP 的浏览器。