不能为Selenium使用chrome驱动程序

时间:2014-03-02 16:19:00

标签: python google-chrome python-3.x selenium python-3.3

我在使用适用于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  

任何帮助将不胜感激。

12 个答案:

答案 0 :(得分:48)

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

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

答案 1 :(得分:28)


适用于Linux

 1.检查您是否安装了最新版本的chrome浏览器 - &gt; &#34; chrome-browser -version&#34;
 2.如果没有,请安装最新版本的chrome &#34; sudo apt-get install chromium-browser&#34;
 3.从http://chromedriver.storage.googleapis.com/index.html获取相应版本的chrome驱动程序  4.解压缩chromedriver.zip
 5.将文件移动到/ usr / bin目录 sudo mv chromedriver / usr / bin
 6.转到/ usr / bin目录,您需要运行类似&#34; chmod a + x chromedriver &#34;标记它可执行。
 7.最后你可以执行代码。

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

答案 2 :(得分:6)

对于Windows

从以下网址下载webdriver:

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

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

现在应该可以了。

from selenium import webdriver
driver = webdriver.Chrome()

答案 3 :(得分:2)

除了选定的答案(窗口样式路径):

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

请注意“C:\ Chrome \ chromedriver.exe”前面的 r ,这会使此字符串成为原始字符串。

如果您不想使用原始字符串,您应该像\\那样转义斜杠,这将变为:

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

或者你可以用/替换\,你会得到这个:

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

答案 4 :(得分:2)

当您调用selenium或任何测试自动化库时,您需要将此处的代码添加到Python中,但这也可以在JavaRuby中完成。

options = webdriver.ChromeOptions()
options.binary_location = '/usr/bin/chromium-browser'
#All the arguments added for chromium to work on selenium
options.add_argument("--no-sandbox") #This make Chromium reachable
options.add_argument("--no-default-browser-check") #Overrides default choices
options.add_argument("--no-first-run")
options.add_argument("--disable-default-apps") 
driver = webdriver.Chrome('/home/travis/virtualenv/python2.7.9/chromedriver',chrome_options=options)

答案 5 :(得分:1)

对于Debian / Ubuntu - 它有效:

为Debian / Ubuntu安装Google Chrome:

wget -N http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver

sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

安装ChromeDriver:

pip install -U selenium

安装Selenium:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.google.co.in/')

Python中的Selenium:

[com.cycorax.ui:ui-mvp-widgets] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.1:jar (attach-javadocs) on project ui-mvp-widgets: Execution attach-javadocs of goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.1:jar failed: A required class was missing while executing org.apache.maven.plugins:maven-javadoc-plugin:2.10.1:jar: org/apache/http/HttpRequest
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-javadoc-plugin:2.10.1
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

答案 6 :(得分:0)

import os   
from selenium import webdriver
chromedriver = "C://chromedriver.exe"                                                                     
os.environ["webdriver.chrome.driver"] = chromedriver                      
driver =webdriver.Chrome(chromedriver)

答案 7 :(得分:0)

您需要做的就是将 Chromedriver.exe 粘贴到 python36-32 文件夹中。您可以使用它简单地说:

from selenium import webdriver
driver = webdriver.Chrome()

无需一次又一次地粘贴路径。


您可以使用:

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

答案 8 :(得分:0)

import os
from selenium import webdriver
chromedriver = "C:\Drivers\chromedriver_win32\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
driver =webdriver.Chrome(chromedriver)
driver.get("https://www.facebook.com")
print(driver.title)
driver.close()

答案 9 :(得分:0)

对于具有虚拟工作区的Windows

首先,检查您的浏览器版本:转到chrome浏览器的最右边3楼并单击它,然后->帮助->关于Google Chrome

一旦您确定我们的浏览器版本,我们就必须从this link

下载并安装chrome驱动器

解压zip文件夹和过去的chromedriver.exe文件  C:\ Users \ name \ virtual_workspace \ Scripts

from selenium import webdriver
wbdriver = webdriver.Chrome()

答案 10 :(得分:-1)

此代码不需要驱动文件的路径:

    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager

    driver = webdriver.Chrome(ChromeDriverManager().install())

答案 11 :(得分:-2)

只需将chromedriver.exe放在python文件夹中(在我的情况下:C:\ Python27)并使用下面提到的代码,它将对你们有用

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("URL")