使用selenium模块控制谷歌浏览器报错

使用selenium模块控制谷歌浏览器报错:

browser=selenium.webdriver.Chrome()
Traceback (most recent call last):
  File "/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/anaconda3/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "visit.py", line 20, in watch_index
    browser=webdriver.Chrome()
  File "/anaconda3/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/anaconda3/lib/python3.7/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

原因是没有在环境中配置chromedriver插件

  • 按照报错给出的网址下载chromedriver压缩文件

使用selenium模块控制谷歌浏览器报错_第1张图片
使用selenium模块控制谷歌浏览器报错_第2张图片

  • 进入下载的文件夹,解压chromedriver压缩文件
unzip chromedriver_mac64.zip 
  • 将解压得到的文件移动到目录/usr/local/bin
mv chromedriver /usr/local/bin
  • 进入/usr/local/bin目录
cd /usr/local/bin
  • 修改权限
chmod a+x chromedirver

此时运行文件不再报错

你可能感兴趣的:(踩的坑,selenium)