TimeoutError: [WinError 10060] :

TimeoutError: [WinError 10060] :

我正在尝试使用 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 以查看它们是否有问题,但它可以正常运行 网络驱动程序位于正确的位置。

感谢任何帮助。

而是仅提供 executable you need to provide the absolute path of the / GeckoDriver 的位置以及扩展名,即 .exe。所以你的有效代码块将是:

  • 对于 ChromeDriver:

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

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

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

driver = webdriver.Firefox(executable_path=locationofDriver)

试一试:

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

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

driver = webdriver.Firefox()