【问题标题】:Could not find a version that satisfies the requirement geckodriver==0.24.0 (from -r /app/requirements.txt (line 4)) error with Selenium Geckodriver找不到满足要求的版本 geckodriver==0.24.0(来自 -r /app/requirements.txt(第 4 行))错误与 Selenium Geckodriver
【发布时间】:2019-06-12 15:04:34
【问题描述】:

我的本​​地机器上没有问题。 但是当我将它部署在云服务器中时,特别是在 Scrapinghub 我需要添加 geckodriver

如何在我的 requirements.txt 中包含 geckodriver?

这是我的工作代码

 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() 

我的 Requirement.txt

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

观察到错误:

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

【问题讨论】:

    标签: selenium firefox scrapy geckodriver selenium-firefoxdriver


    【解决方案1】:

    此错误消息...

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

    ...暗示 GeckoDriver 尝试通过 Firefox 启动浏览会话时出现错误。

    根据@987654321 中的文档,geckodriver==0.24.0selenium==3.13.0 之间似乎没有不兼容性 @。

    大概是 Mozilla Firefox 的安装位置有问题。 Firefox 未安装在您的系统中,或者 Firefox 未安装在 默认(所需的)位置。


    解决方案

    您需要在默认位置安装 Firefox。如果 Firefox 安装在 自定义 位置,您需要传递 firefox 二进制文件绝对路径,如下所示:

    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")
    

    【讨论】:

    • 嗨@debanjanB,我不能使用本地路径,因为我通过云服务器专门在scrapinghub 中部署它。我在本地机器上使用脚本时没有问题。
    • @ChristianRead 好吧,我看到这个问题就像 Google CoLab 场景一样。我的观点是,要使用 Selenium 和 GeckoDriver,您需要确定安装 Mozilla Firefox。
    • 是的,我们会注意到这一点,感谢您对我的帮助。将尝试其他方法来解决此问题
    • @ChristianRead 供您参考这里是Google Colab issue,我们在其中讨论了与 ChromeDriver / Chrome 安装类似的问题。
    猜你喜欢
    • 2021-04-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2020-07-24
    • 1970-01-01
    • 2021-02-11
    • 2020-09-24
    • 2020-12-05
    相关资源
    最近更新 更多