【问题标题】:Selenium Python - WebdriverSelenium Python - 网络驱动程序
【发布时间】:2018-10-20 14:27:00
【问题描述】:

我正在使用 selenium 爬取一个 javascript 网站,问题是打开了一个 Firefox 浏览器,但没有完成对 URL 的调用。但是,当我关闭浏览器时,就完成了对 URL 的调用,当然我得到了缺少的驱动程序异常。你认为这个问题是从哪里来的。

知道:

  • 所有程序都是最新的
  • 我的解决方案在本地运行良好,但是当我尝试在服务器上部署它时,我开始遇到问题

示例:在我的本地机器上,我运行这个脚本,一切都很顺利,但是当我在服务器 (Linux) 上运行它时,只有浏览器打开并且没有调用 get URL

from selenium import webdriver
import time

geckodriver_path = r'.../geckodriver'

driver = webdriver.Firefox(executable_path= geckodriver_path)
time.sleep(3)
driver.get("http://www.stackoverflow.com")

【问题讨论】:

  • 请添加您的异常日志。
  • 异常并不重要,因为是我在关闭浏览器时生成的:selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 0
  • 我的问题更多是关于为什么浏览器保持打开状态而不传递将完成对 url 的调用的部分
  • 请附上说明问题的minimal reproducible example

标签: python selenium


【解决方案1】:

我最终找到了解决方案:

from selenium import webdriver
import time
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

geckodriver_path = r'/path_to/geckodriver'

binary = FirefoxBinary(r'/usr/bin/firefox')

capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities["marionette"] = False

driver = webdriver.Firefox(firefox_binary=binary,
                           executable_path= geckodriver_path,
                           capabilities=capabilities)

time.sleep(3)
driver.get("https://stackoverflow.com/")
time.sleep(6)
driver.close()

# solution from: 
# https://github.com/SeleniumHQ/selenium/issues/3884
# https://stackoverflow.com/questions/25713824/setting-path-to-firefox-binary-on-windows-with-selenium-webdriver

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多