【问题标题】:how to get selenium dependency chromedriver installed up and running [duplicate]如何安装并运行 selenium 依赖 chromedriver [重复]
【发布时间】:2019-09-17 12:13:30
【问题描述】:

我收到此错误:

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


    【解决方案1】:

    不要单独运行 chromedriver。在脚本中设置路径:

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

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

    【讨论】:

    • 试过但没有帮助
    【解决方案2】:

    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)
    

    【讨论】:

    • 试过但没有帮助
    猜你喜欢
    • 2016-01-14
    • 2019-04-13
    • 2018-04-28
    • 2019-11-30
    • 2019-07-09
    • 2014-10-24
    • 2017-05-21
    • 2016-04-26
    • 1970-01-01
    相关资源
    最近更新 更多