Selenium实际上并没有控制Firefox

时间:2017-11-20 14:37:41

标签: python selenium firefox

我真的不确定我的节目有什么问题。它上周正在运行,我甚至没有更改任何代码,但现在当我运行我的刮刀,在firefox打开后,没有任何事情发生很长一段时间,然后我得到以下错误

Traceback (most recent call last):
File "C:/Users/usernameredracted/PycharmProjects/scraper - Copy/demospider.py", line 179, in <module>
scrapeit()
File "C:/Users/usernameredracted/PycharmProjects/scraper - Copy/demospider.py", line 47, in scrapeit
driver = init_driver()
File "C:/Users/usernameredracted/PycharmProjects/scraper - Copy/demospider.py", line 16, in init_driver
driver = webdriver.Firefox()
File "C:\Users\usernameredracted\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__
keep_alive=True)
File "C:\Users\usernameredracted\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\usernameredracted\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Users\usernameredracted\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "C:\Users\usernameredracted\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

我尝试了(selenium.common.exceptions.WebDriverException: Message: connection refused)中列出的解决方案,但这给我带来了不同的错误

OSError=[WinError 2] The system cannot find the file specified
Program install error! 

有关如何做的任何建议?

1 个答案:

答案 0 :(得分:0)

试试这个。

首先更新selenium:pip install -U selenium然后更新您的geckodriver

https://github.com/mozilla/geckodriver/releases

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = False
driver = webdriver.Firefox(capabilities=firefox_capabilities)

https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

  

使用Selenium 3.0及更高版本,您不需要做任何事情就可以使用   木偶,因为它默认启用。

这可能是牵线木偶中的一些未知错误,尝试使用上面的代码禁用它以使用好的旧geckodriver,如果失败也向我们显示提示。