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://,改正后如下:

  • 相关阅读:
    [转]OOA/OOD/OOP区别
    Get / Post
    1.PHP环境搭配
    6.WCF Rest
    消除关闭按钮时的IE弹出提示
    TSQL DML学习笔记
    javascript 中类的定义
    $().each() 与 $.each()区别,以及 jquery ajax 应用
    TSQL 数据库的创建
    删除用户表 存储过程 索引..
  • 原文地址:https://www.cnblogs.com/RzCong/p/8449911.html
Copyright © 2011-2022 走看看