【问题标题】:Webdriver does not access webpage no matter what browser I use [duplicate]无论我使用什么浏览器,Webdriver都无法访问网页[重复]
【发布时间】:2019-05-31 10:39:00
【问题描述】:

我正在尝试使用 Selenium 的网络驱动程序访问网页,但无论我使用哪种浏览器 (Opera/Firefox/GoogleChrome),我都无法访问该网页。

在任何情况下,浏览器都会弹出并挂在那里,不访问任何 URL。

当我尝试运行我的脚本时,我得到了

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /usr/bin/[opera/chrome]

如果我使用 Firefox,我会得到:

selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/firefox unexpectedly exited. Status code was: 0

我的代码:

browser = webdriver.Firefox(executable_path=FIREFOX_PATH)

browser.get('www.google.com')
r = BeautifulSoup(browser.page_source, PARSER)
print(r.text)

我正在使用带有 python3.6 的 Linux Ubuntu 18.04

【问题讨论】:

标签: python python-3.x selenium selenium-webdriver


【解决方案1】:

由于您使用executable_path=FIREFOX_PATH 创建了 webdriver,我认为您可能混淆了 Firefox 二进制文件和 geckodriver 二进制文件的路径的关键字参数。 webdriver.Firefox 期待:

  • firefox_binary – FirefoxBinary 实例或 Firefox 二进制文件的完整路径。如果未定义,将使用系统默认的 Firefox 安装。
  • executable_path – 覆盖用于 Firefox 47.0.1 及更高版本的 geckodriver 二进制文件的完整路径,默认从系统路径中获取二进制文件。

因此,对于 Firefox 二进制文件 firefox,您需要设置关键字参数 firefox_binary。对于 geckodriver 二进制文件geckodriver,您需要设置关键字参数executable_path。


您是否甚至想要/需要使用默认二进制文件以外的其他文件?你能跑吗

firefox --version

和

geckodriver --version

在您的终端中没有问题?那么你根本不需要设置firefox_binary 或executable_path。

【讨论】:

    猜你喜欢
    • 2016-12-11
    • 1970-01-01
    • 2012-05-10
    • 2016-01-09
    • 2014-05-24
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多