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

0x01 问题

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

具体代码:

from selenium import webdriver
browser = webdriver.Chrome()

运行报错

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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环境变量中。####

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容