简体   繁体   中英

Selenium not actually controlling Firefox

I'm genuinely unsure as to what's wrong with my program. It was functioning last week, and I didn't even change any code, but now when I run my scraper, after firefox opens up, nothing happens for quite some time, and then I get the following error

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

I tried the solution listed in ( selenium.common.exceptions.WebDriverException: Message: connection refused ) but that got me a different error

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

Any advice on what to do?

Try this.

First update selenium: pip install -U selenium then update your 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

With Selenium 3.0 and later, you shouldn't need to do anything to use Marionette, as it's enabled by default.

It could be some unknown bug in marionette, try disabling it with the code above to use the good old geckodriver, if it fails too show us the prompt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM