zoukankan      html  css  js  c++  java
  • python脚本中selenium启动浏览器报错os.path.basename(self.path), self.start_error_message) selenium.common.excep

    转载:https://blog.csdn.net/weixin_44612439/article/details/87983282
    python脚本中selenium启动浏览器报错os.path.basename(self.path), self.start_error_message) selenium.common.excep      
                               
                       
                       
                                                在python脚本中,使用selenium启动浏览器报错,原因是未安装浏览器驱动,报错内容如下:
    # -*- coding:utf-8 -*-
    from selenium import webdriver
    driver = webdriver.Firefox()
    driver.get("http://www.baidu.com")
    12345
    报错提示如下所示:
    Traceback (most recent call last):
      File "D:Program FilesPython36libsite-packagesseleniumwebdrivercommonservice.py", line 76, in start
        stdin=PIPE)
      File "D:Program FilesPython36libsubprocess.py", line 709, in __init__
        restore_signals, start_new_session)
      File "D:Program FilesPython36libsubprocess.py", line 997, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] 系统找不到指定的文件。
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "D:/Program Files/Python36/baidu.py", line 4, in <module>
        driver = webdriver.Firefox()
      File "D:Program FilesPython36libsite-packagesseleniumwebdriverfirefoxwebdriver.py", line 164, in __init__
        self.service.start()
      File "D:Program FilesPython36libsite-packagesseleniumwebdrivercommonservice.py", line 83, in start
        os.path.basename(self.path), self.start_error_message)
    selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
    12345678910111213141516171819

    解决方案:安装Chrome浏览器驱动
    1.下载 chromedriver_win32.zip,根据浏览器版本下载对应的压缩包;
    下载地址:https://sites.google.com/a/chromium.org/chromedriver/downloads
    2.解压后将chromedriver.exe文件放到系统环境变量Path路径下,例如:已将D:Program FilesPython36 添加到系统环境变量Path路径下,将chromedriver.exe文件放到D:Program FilesPython36 目录下即可;
    3.将Chrome替换掉原脚本中的Firefox,保存文件并运行。
    # -*- coding:utf-8 -*-
    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get("http://www.baidu.com")
    driver.find_element_by_id("kw").send_keys("Selenium2")
    driver.find_element_by_id("su").click
    driver.quit()
    ————————————————
  • 相关阅读:
    《挑战程序设计竞赛》 读后感
    基于SOAP的xml网络交互心得
    不用客户端,轻松下视频
    在cmd窗口中查询android的sqlite3数据库表之步骤
    单链表的插入删除以及逆转
    java中排序一个字符串数组
    求质因数
    指针与引用的区别
    统计查询-sql
    ---随心买统计查询
  • 原文地址:https://www.cnblogs.com/yuany66/p/12409749.html
Copyright © 2011-2022 走看看