我的本地计算机上没有问题。 但是当我将其部署在Scrapinghub中的云服务器中时 我需要添加geckodriver
如何在我的require.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)
答案 0 :(得分: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 启动浏览会话时出错。
根据{{中的文档, geckodriver == 0.24.0 和 selenium == 3.13.0 之间似乎没有不兼容性 3}}。
大概是 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")