Search code examples
seleniumfirefoxscrapygeckodriverselenium-firefoxdriver

Could not find a version that satisfies the requirement geckodriver==0.24.0 (from -r /app/requirements.txt (line 4)) error with Selenium Geckodriver


There's no problem on my local machine. But when I deployed it in cloud server specifically in Scrapinghub I need to add geckodriver

How can include geckodriver in my requirement.txt?

here's my working code

 from selenium import webdriver
 from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.common.by import By
 from selenium.webdriver.support import expected_conditions as EC
 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
 from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

 def parse_subpage(self, response):

        profile = webdriver.FirefoxProfile()
        profile.set_preference("network.proxy.type", 1)
        profile.set_preference("network.proxy.http", 
                    "localhost")
        profile.set_preference("network.proxy.http_port", 
                    3128)
        profile.update_preferences()

        capabilities = webdriver.DesiredCapabilities().FIREFOX
        capabilities["marionette"] = True
        driver = webdriver.Firefox(capabilities=capabilities, 
                    firefox_profile=profile)

        driver.get('sample.com')
        driver.quit() 

my Requirement.txt

mysql-connector-python
pytz==2018.9
selenium==3.13.0
geckodriver==0.24.0 

Error observed:

ERROR: Could not find a version that satisfies the requirement geckodriver==0.24.0 (from -r /app/requirements.txt (line 4)) (from versions: none)

Solution

  • This error message...

    Could not find a version that satisfies the requirement geckodriver==0.24.0 (from -r /app/requirements.txt (line 4)) (from versions: none)
    

    ...implies that the there was an error while GeckoDriver tried to initiate a browsing session through Firefox.

    Seems there is no incompatibility between geckodriver==0.24.0 and selenium==3.13.0 as per the documentation in Supported platforms.

    Presumably, it looks like an issue with the installation location of Mozilla Firefox. Either Firefox is not installed within your system or Firefox is not installed at the default (desired) location.


    Solution

    You need to have Firefox installed at the default location. Incase Firefox is installed at a customized location you need to pass the absolute path of the firefox binary as follows:

    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    
    capabilities = webdriver.DesiredCapabilities().FIREFOX
    capabilities["marionette"] = True
    binary = FirefoxBinary('C:/Program Files/Mozilla Firefox/firefox.exe')
    driver = webdriver.Firefox(firefox_binary=binary, capabilities=capabilities, executable_path="C:/Utility/BrowserDrivers/geckodriver.exe")
    driver.get("http://www.google.com")