Message: 'chromedriver' executab

2022-11-04  本文已影响0人  _Gaara_

刚学python,遇到的第一个问题就是模仿浏览器行为的时候报错。
代码很简单:

from selenium.webdriver import Chrome
web = Chrome() 
web.get('https://www.baidu.com')
web.close()

然后报错

    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

原来是缺浏览器。
网上的解决方案都不太认可。我的办法是,先下载对应的文件。
[这里下载](http://chromedriver.storage.googleapis.com/index.html
然后将它放进你的项目目录里,然后直接将它引到你项目即可

from selenium.webdriver import Chrome 

chromedriver = '/Users/gaara/Documents/Python/MovieInfo/chromedriver'
# web = Chrome()
web = Chrome(executable_path=chromedriver)
web.get('https://www.baidu.com')
web.close()
上一篇 下一篇

猜你喜欢

热点阅读