如何安装并运行硒依赖项chromedriver

时间:2019-04-28 19:14:01

标签: python selenium selenium-webdriver selenium-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.

2 个答案:

答案 0 :(得分:2)

请勿单独运行chromedriver。可以使用以下命令在脚本中设置路径:

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

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

答案 1 :(得分:0)

chromedriver<dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-lambda-java-core</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>com.google.firebase</groupId> <artifactId>firebase-admin</artifactId> <version>6.7.0</version> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-s3</artifactId> <version>1.11.483</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.6.2</version> <scope>test</scope> </dependency> <dependency> <groupId>com.stripe</groupId> <artifactId>stripe-java</artifactId> <version>9.7.0</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version> </dependency> </dependencies> 脚本放在同一文件夹

并执行以下操作:

.py