selenium python 加载页面问题 driver.get('http://page.com/') 打开为空 window

selenium python problem with loading page driver.get('http://page.com/') open empty window

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary


browser = webdriver.Firefox(executable_path=r'/usr/bin/firefox')
browser.get("http://google.com/")

Ubuntu 16 LTS 用户 here.How 在我输入 url 并且那里没有加载页面后修复这个空 window 问题。

输出:

> > Traceback (most recent call last):   File "/home/pc/PycharmProjects/calculator/test.py", line 781, in <module>
>     browser = webdriver.Firefox(executable_path=r'/usr/bin/firefox')   File
> "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py",
> line 164, in __init__
>     self.service.start()   File "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
> line 98, in start
>     self.assert_process_still_running()   File "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
> line 111, in assert_process_still_running
>     % (self.path, return_code) selenium.common.exceptions.WebDriverException: Message: Service
> /usr/bin/firefox unexpectedly exited. Status code was: 0

您需要提供 geckodriver 路径而不是 firefox。检查您的 firefox 浏览器版本,您可以从 Here

下载兼容的 geckodriver
browser = webdriver.Firefox(executable_path="path of geckodriver")

示例代码

browser = webdriver.Firefox(executable_path="/Users/username/Location/geckodriver")

browser.get("https://google.com")

您可以在PATH系统变量

中添加您的网络驱动程序的路径
export PATH=$PATH:/path/to/driver/firefox-driver

将其添加到 /home//.profile 文件以使其永久化。

那你就不需要了 executable_path=''