无法使用 Selenium 的 chrome 驱动程序

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

我在使用 Selenium 的 Chrome 驱动程序时遇到问题。我已下载 chromedriver 并将其保存到 C:\Chrome:

driver = webdriver.Chrome(executable_path="C:/Chrome/")

使用它会给我以下错误:

Traceback (most recent call last):
  File "C:\Python33\lib\subprocess.py", line 1105, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\service.py", line 63, in start
    self.service_args, env=env, stdout=PIPE, stderr=PIPE)
  File "C:\Python33\lib\subprocess.py", line 817, in __init__
    restore_signals, start_new_session)
  File "C:\Python33\lib\subprocess.py", line 1111, in _execute_child
    raise WindowsError(*e.args)
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Wilson/Dropbox/xxx.py", line 71, in <module>
    driver = webdriver.Chrome(executable_path="C:/Chrome/")
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
    self.service.start()
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\service.py", line 68, in start
    and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.                 Please download from http://chromedriver.storage.googleapis.com/index.html  

如有任何帮助,我们将不胜感激。

python google-chrome python-3.x selenium python-3.3
4个回答
62
投票

您应该指定可执行文件路径,而不是包含可执行文件的目录路径。

driver = webdriver.Chrome(executable_path=r"C:\Chrome\chromedriver.exe")

36
投票


对于Linux

1. 检查您是否安装了最新版本的chrome浏览器-> “chromium-browser -version”
2. 如果没有,请安装最新版本的 chrome “sudo apt-get install chromium-browser”
3. 从 http://chromedriver.storage.googleapis.com/index.html
获取适当版本的 chrome 驱动程序 4.解压chromedriver.zip
5. 将文件移至 /usr/bin 目录 sudo mv chromedriver /usr/bin
6. 转到 /usr/bin 目录,您需要运行“chmod a+x chromedriver”之类的命令将其标记为可执行。
7.终于可以执行代码了。

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
display.stop()

8
投票

对于窗户

从以下位置下载网络驱动程序:

http://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip

将 chromedriver.exe 文件粘贴到“C:\Python27\Scripts”文件夹中。

现在应该可以了。

from selenium import webdriver
driver = webdriver.Chrome()

4
投票

除了选择的答案(windows风格路径):

driver = webdriver.Chrome(executable_path=r"C:\Chrome\chromedriver.exe")

注意“C:\Chrom”前面的r

© www.soinside.com 2019 - 2024. All rights reserved.