如何让硒依赖ChromeDriver安装并运行



我收到此错误:

Traceback (most recent call last):
  File "facebookFOF.py", line 19, in <module>
    driver = webdriver.Chrome(chrome_options=chrome_options)
  File "/Users/ciasto/pyenvs/fbgraph/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()
  File "/Users/ciasto/pyenvs/fbgraph/lib/python2.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

转到上面显示的chrome驱动程序网址并下载了适用于我的mac操作系统的设置,我运行了它,但卡在:

ciasto$ /Users/ciasto/Downloads/chromedriver; exit
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 9515
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

不要单独运行 chromedriver。使用以下方法在脚本中设置路径:

driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.

或者按照建议,将其添加到您的 PATH 中。

将 chromedriver 放在与.py脚本相同的文件夹中

并执行以下操作:

import os
from selenium import webdriver
BASE_PATH = os.path.abspath(os.path.dirname(__file__)) # get script directory 
CHROME_DRIVER_PATH = os.path.join(BASE_PATH, 'chromedriver') # create chrome driver path
driver =  webdriver.Chrome(executable_path = CHROME_DRIVER_PATH)

最新更新