selenium.common.exceptions.WebDriverException: Message: Service chromium-browser unexpectedly exited

来源:互联网 发布:php csdn博客 编辑:程序博客网 时间:2024/05/16 10:12

Python新手。今天在学习Python使用selenium和webdriver打开chrome浏览器,遇到两个问题

from selenium import webdriverbrowser = webdriver.chrome("chromium-browser")browser.get("http://www.baidu.com")

然后报错如下:

Traceback (most recent call last):
File “test.py”, line 3, in < module >
browser = webdriver.Chrome(“chromium-browser”)
File “/usr/lib/python2.7/selenium/webdriver/chrome/webdriver.py”, line 62, in _ init_
self.service.start()
File “/usr/lib/python2.7/selenium/webdriver/common/service.py”, line 96, in start
self.assert_process_still_running()
File “/usr/lib/python2.7/selenium/webdriver/common/service.py”, line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service chromium-browser unexpectedly exited. Status code was: 0

这个错误的原因是webdriver.Chrome(“chromium-browser”),参数不应该是chrome浏览器,而应该是chromedriver,于是下载chromedriver即可,我的系统是Ubuntu 14.04,下载解压之后移动到/usr/bin目录下。

改为如下之后遇到新的问题:

from selenium import webdriverbrowser = webdriver.chrome("chromedriver")browser.get("http://www.baidu.com")

Traceback (most recent call last):
File “test.py”, line 4, in < module>
browser.get(‘http://www.baidu.com‘)
File “/usr/lib/python2.7/selenium/webdriver/remote/webdriver.py”, line 264, in get
self.execute(Command.GET, {‘url’: url})
File “/usr/lib/python2.7/selenium/webdriver/remote/webdriver.py”, line 252, in execute
self.error_handler.check_response(response)
File “/usr/lib/python2.7/selenium/webdriver/remote/errorhandler.py”, line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {“code”:-32603,”message”:”Cannot navigate to invalid URL”}
(Session info: chrome=49.0.2623.108)
(Driver info: chromedriver=2.9.248304,platform=Linux 3.16.0-30-generic x86_64)

不知道具体原因,欢迎知道的朋友告知一下,在Google上看见一个朋友写的代码,试了一下,结果问题解决了,成功打开页面。

import osfrom selenium import webdriverchromedriver = "/usr/bin/chromedriver"os.environ["webdriver.chrome.driver"] = chromedriverbrowser = webdriver.Chrome('chromedriver')browser.get('http://www.baidu.com')
0 0
原创粉丝点击