zoukankan      html  css  js  c++  java
  • Python- Anacoda环境使用Selenium+ChromeDriver报错

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

    pip install selenium  

    报错具体如下:

    driver=webdriver.Chrome()
    Traceback (most recent call last):
      File "D:appAnacondalibsite-packagesseleniumwebdrivercommonservice.py", line 76, in start
        stdin=PIPE)
      File "D:appAnacondalibsubprocess.py", line 947, in __init__
        restore_signals, start_new_session)
      File "D:appAnacondalibsubprocess.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:appAnacondalibsite-packagesseleniumwebdriverchromewebdriver.py", line 68, in __init__
        self.service.start()
      File "D:appAnacondalibsite-packagesseleniumwebdrivercommonservice.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:appAnacondaScripts下,重新运行命令即可打开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:appAnacondalibsite-packagesseleniumwebdriver
    emotewebdriver.py", line 324, in get
        self.execute(Command.GET, {'url': url})
      File "D:appAnacondalibsite-packagesseleniumwebdriver
    emotewebdriver.py", line 312, in execute
        self.error_handler.check_response(response)
      File "D:appAnacondalibsite-packagesseleniumwebdriver
    emoteerrorhandler.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://,改正后如下:

  • 相关阅读:
    windows快速安装redis
    Tensorflow教程(3)什么是张量?什么是数据流图?
    Tensorflow教程(2)Tensorflow的常用函数介绍
    Tensorflow教程(1)Tensorflow的下载和安装
    oracle获取当天时间的最开始的时间和最结尾的时间
    kindeditor在线文本编辑器过滤HTML的方法
    用PHP抓取淘宝商品的用户晒单评论+图片实例
    用PHP抓取百度贴吧邮箱数据
    微信公众号天气查询接口实例
    【Python】自动化升级所有pip安装的包
  • 原文地址:https://www.cnblogs.com/RzCong/p/8449911.html
Copyright © 2011-2022 走看看