【问题标题】:Selenium Python can't connect to website with proxySelenium Python 无法使用代理连接到网站
【发布时间】:2020-09-23 20:42:41
【问题描述】:

我正在尝试将 Selenium 与 chrome 驱动程序一起使用并使用代理连接到网站,但由于某些奇怪的原因,chrome 会返回一个错误,即连接已重置或连接超时或无法访问此站点等等。 . 使用了很多代理,所以我怀疑代理服务器有问题。

这是我的代码:

from selenium import webdriver

chromedriver = r'C:/Users\seife\Documents\chromedriver\chromedriver.exe'
PROXY = "177.202.59.58:8080"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)
chrome = webdriver.Chrome(chromedriver, options=chrome_options)
chrome.get("http://whatismyipaddress.com")

页面如下所示:

【问题讨论】:

    标签: python selenium proxy selenium-chromedriver


    【解决方案1】:
    #you need to import Options 
    from selenium.webdriver.chrome.options import Options
    from selenium import webdriver
    
    chromedriver = r'C:/Users\seife\Documents\chromedriver\chromedriver.exe'
    PROXY = "177.202.59.58:8080"  #free proxies sometimes don't work, I tried with netherland's proxy, and it worked
    chrome_options = Options()   #here is the change
    chrome_options.add_argument('--proxy-server=%s' % PROXY)
    chrome = webdriver.Chrome(chromedriver, options=chrome_options)
    chrome.get("https://whatismyipaddress.com")   #and here is the change, just https
    

    【讨论】:

    • 我进行了更改,使用了许多代理,包括您的代理,但仍然无法连接;/,您的 chrome 版本是什么??无论如何,感谢您的帮助,我很感激!。
    • sslproxies.org 尝试使用不同的代理。我的 chrome 版本是 83。您是否尝试过更改标题?
    • 尝试更改用户代理。您可以从 user-agents.net 获得免费的用户代理,也可以使用 fake_headers 模块。 “chrome_options.add_argument(f'user-agent={user-agent}')”类似这样的
    • 我有 v.81 chromedriver,也许我的 idk 已经过时了。它可以工作,但超级慢?可能是因为免费代理。
    • 是的,免费代理大多很慢,你也可以使用 VPN
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 2020-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多