查看: 1486|回复: 1

selenium.common.exceptions.WebDriverException:消息:'chromedriver'可执...

[复制链接]

22

主题

107

帖子

266

积分

中级会员

Rank: 3Rank: 3

积分
266
发表于 2018-9-19 08:14:21 | 显示全部楼层 |阅读模式
当我运行我的脚本时,我收到了这个错误
Traceback (most recent call last):
  File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 992, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/ishaq/AppData/Local/Programs/Python/Python36/headless.py", line 9, in <module>
    driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"),   chrome_options=chrome_options)
  File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 81, 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
回复

使用道具 举报

15

主题

97

帖子

310

积分

论坛管理

Rank: 4

积分
310
发表于 2018-9-19 08:16:02 | 显示全部楼层
分析日志,主要问题是 start os.path.basename(self.path)和后续的错误消息selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH。
因此从上面消息中可以清楚地看出Python无法找到chromedriver二进制文件。
你必须在这里处理几点:
1.        chrome_options.binary_location:参数配置是chrome.exe而不chromedriver.exe
2.        os.path.abspath("chromedriver")将获取文件路径chromedriver但不会追加chromedriver.exe到最后。
3.        这里是Windows 8系统的示例代码,以Headless Mode运行chrome。
  1. from selenium import webdriver  
  2. from selenium.webdriver.chrome.options import Options

  3. chrome_options = Options()  
  4. chrome_options.add_argument("--headless")  
  5. driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')  
  6. driver.get("http://www.duo.com")
  7. print("Chrome Browser Initialized in Headless Mode")
  8. driver.quit()
  9. print("Driver Exited")
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表