近来准备写个脚本去搜索某端游的官网交易平台。因为也不懂高端的爬虫技术,决定用selenium去戳。这里采用的是chrome浏览器,链接网页时报错:

File "C:\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Python37\lib\site-packages\selenium\webdriver\common\service.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

 

解决办法:

安装与浏览器版本匹配的 webdriver

1、打开谷歌浏览器, 在地址栏输入 chrome://version/  查看版本信息,我的版本信息描述如下:

Google Chrome 72.0.3626.119 (正式版本) (32 位) (cohort: Stable)
修订版本 9a65993e2cde1b5797ec98da4cd9abcea464cd7b-refs/branch-heads/3626@{#876}
操作系统 Windows

2、选择合适版本的驱动下载, 如果没有完全匹配的就选最相似匹配的版本下载。(比如我的版本没有完全匹配的,我选了一个临近的驱动,也可用)

下载地址:

http://chromedriver.storage.googleapis.com/index.html

 

3、解压下载的驱动放到指定目录,代码调用时指定该目录即可。

我把它放在了 selenium 下的 chrome 了,代码演示如下

from selenium import webdriver

chrome_driver = r"C:\Python37\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe"
browser = webdriver.Chrome(executable_path=chrome_driver)

成功解决问题!

posted on 2020-01-10 11:07  云雀sunshine  阅读(574)  评论(0编辑  收藏  举报