美文网首页
Message: 'chromedriver' executab

Message: 'chromedriver' executab

作者: _Gaara_ | 来源:发表于2022-11-04 16:45 被阅读0次

刚学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()

相关文章

网友评论

      本文标题:Message: 'chromedriver' executab

      本文链接:https://www.haomeiwen.com/subject/pocutdtx.html