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

本文介绍了在Windows环境下,如何解决使用Python的Selenium库配合ChromeDriver启动Chrome浏览器时遇到的错误。文中详细阐述了ChromeDriver的作用、兼容性要求及正确的安装配置步骤。

 

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

pip install selenium  

报错具体如下:

driver=webdriver.Chrome()
Traceback (most recent call last):
  File "D:\app\Anaconda\lib\site-packages\selenium\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\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
    self.service.start()
  File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/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: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.16299 x86_64)

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

 

转载于:https://www.cnblogs.com/RzCong/p/8449911.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值