【解决】关于selenium的webdriver调用Chrome时报错的解决方案

0x01 问题

最近在学习爬虫来着,遇到了在安装selenium时调用Chrome时报错的情况,记录一下。

具体代码:

from selenium import webdriver
browser = webdriver.Chrome()

运行报错

Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Python27\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

0x02 解决

下载chromedriver,网址https://sites.google.com/a/chromium.org/chromedriver/downloads

下载之后将chromedriver.exe放到一个目录下,我是放到了chrome.exe一个目录下了,

C:\Program Files (x86)\Google\Chrome\Application

也可以根据自己需求,放到喜欢的目录下。

但是一定要记得把该目录添加到PATH环境变量中。####

之后在运行代码,就弹出了浏览器了。

【解决】关于selenium的webdriver调用Chrome时报错的解决方案_第1张图片

你可能感兴趣的:(【解决】关于selenium的webdriver调用Chrome时报错的解决方案)