Python- Anacoda环境使用Selenium+ChromeDriver报错

 

我的系统是win10,python是用Anacoda安装的,通过pip安装了selenium 后使用Chromedriver发现报错,pip安装selenium如下:

1
pip install   

报错具体如下:

复制代码
driver=webdriver.Chrome()
Traceback (most recent call last):
  File "D:\app\Anaconda\lib\site-packages\\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "D:\app\Anaconda\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "D:\app\Anaconda\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\app\Anaconda\lib\site-packages\\webdriver\chrome\webdriver.py", line 68, in __init__
    self.service.start()
  File "D:\app\Anaconda\lib\site-packages\\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
.common.exceptions.WebDriverException: Message: '' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org//home
复制代码

selenium操作chrome浏览器需要有ChromeDriver驱动来协助。

什么是ChromeDriver?
ChromeDriver是Chromium team开发维护的,它是实现WebDriver有线协议的一个单独的服务。ChromeDriver通过chrome的自动代理框架控制浏览器,ChromeDriver只与12.0.712.0以上版本的chrome浏览器兼容。

 

解决办法:

1.下载Chromedriver,网盘:https://pan.baidu.com/s/1c3KLRJa

2.把Chromedriver解压到D:\app\Anaconda\Scripts\下,重新运行命令即可打开Chromedriver

在运行了

driver=webdriver.Chrome()
driver.get('www.baidu.com')

之后出现报错:

复制代码
>>> driver.get('m.weibo.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 324, in get
    self.execute(Command.GET, {'url': url})
  File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
  (Session info: chrome=63.0.3239.132)
  (Driver info: =2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.16299 x86_64)
复制代码

原因是打开的域名一定要加前http://,改正后如下:

 

 

人已赞赏
博客

Docker-

2019-8-18 16:40:30

博客

MySQL- 常用的MySQL函数,指令等

2019-8-18 16:44:08

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索