在运行此代码时
from selenium import webdriver
driver = webdriver.Chrome("/usr/bin/google-chrome")
使用新选项卡打开浏览器后退出此错误
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: 0
之后我无法使用驱动变量,因为它返回一个NameError。
我用pip安装了selenium,我使用的是python 3.5.3。
我忘了提到我正在使用Ubuntu 17.04 zesty
当您使用Selenium 3.x.x
以及最近的Google Chrome
浏览器时,您必须从chromedriver.exe
下载this location将它放在您的系统中,并通过chromedriver
参数提及executable_path
二进制文件的绝对位置,如下所示:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()