【Python 解决错误】selenium.common.exception.WebDriverException

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

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/homeweb

 

解决办法:chrome

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

一、打开谷歌浏览器, 在地址栏输入 chrome://version/  查看版本信息,个人版本信息描述以下:浏览器

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

二、选择合适版本的驱动下载, 若是没有彻底匹配的就选最类似匹配的版本下载。(好比个人版本没有彻底匹配的,我选了一个临近的驱动,也可用)google

下载地址:spa

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

 

三、解压下载的驱动放到指定目录,代码调用时指定该目录便可。操作系统

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

from selenium import webdriver

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

成功解决问题!blog

相关文章
相关标签/搜索