如何安装和运行selenium依赖chromedriver [重复]

问题描述 投票:0回答:2

我收到此错误:

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驱动程序URL并下载了我的mac os的设置,我跑了但是卡在了:

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.
python selenium selenium-webdriver selenium-chromedriver
2个回答
2
投票

不要单独使用chromedriver。使用以下命令在脚本中设置路径:

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

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


0
投票

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)
© www.soinside.com 2019 - 2024. All rights reserved.