【问题标题】:TimeoutError: [WinError 10060] :超时错误:[WinError 10060]:
【发布时间】:2020-08-07 14:14:03
【问题描述】:

我正在尝试使用 selenium 连接到我的 Firefox 浏览器。

#Initialise Firefox
print("here")
locationofDriver = "C:/Users/barry/OneDrive/Documents/Webdriver/"
print("here2")
driver = webdriver.Firefox(locationofDriver)
print("here3")

但我得到两个错误:

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

还有:

urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))

打印语句的输出:

here
here2

我手动启动了 Firefox 以查看它们是否存在问题,但它功能完善 网络驱动程序位于正确的位置。

任何帮助表示赞赏。

【问题讨论】:

    标签: python selenium selenium-webdriver selenium-chromedriver geckodriver


    【解决方案1】:

    您需要提供ChromeDriver / GeckoDriver绝对路径以及扩展名,即.exe,而不是只提供WebDriver 可执行文件的位置。所以你的有效代码块将是:

    • 对于ChromeDriver

      locationofDriver = r'C:/Users/barry/OneDrive/Documents/Webdriver/chromedriver.exe'
      
    • 对于GeckoDriver

      locationofDriver = r'C:/Users/barry/OneDrive/Documents/Webdriver/geckodriver.exe'
      

    最后,您可以将 key executable_pathalong value 传递如下:

    driver = webdriver.Firefox(executable_path=locationofDriver)
    

    【讨论】:

      【解决方案2】:

      试试看:

      locationofDriver = "<path to file>/geckodriver.exe"
      

      或者将geckodriver.exe添加到有工作python文件的目录,然后你可以尝试:

      driver = webdriver.Firefox()
      

      【讨论】:

      • 我收到错误 NotADirectoryError: [WinError 267] 目录名称无效:'C:/Users/barry/OneDrive/Documents/Webdriver/geckodriver.exe'
      • 检查您到geckodriver.exe 的路径。您必须写入此文件的正确路径。尝试将 geckodriver.exe 添加到包含工作 python 文件的目录。
      猜你喜欢
      • 2020-09-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      • 2022-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多