selenium - chromedriver可执行文件需要在PATH中

时间:2016-11-11 20:44:49

标签: python selenium selenium-chromedriver

引用错误消息:' chromedriver'可执行文件需要在PATH中

我试图在pycharm中使用selenium编写脚本代码。但后来我得到了上述错误。我已将我的selenium链接到pycharm,如下所示:https://gyazo.com/b5622e3165bbfd93cfa205178df79b6f - (新鲜且最新)

我是selenium的新手,不是文件夹中的chromedriver。" selenium。" 如果它不在哪里可以找到并将其添加到路径中?

顺便说一句,我试着打字" chromedriver"在cmd中,它不被识别为内部或外部命令。

错误如下所示:

Traceback (most recent call last):
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/sebastian/PycharmProjects/web/bot.py", line 10, in <module>
    browser = webdriver.Chrome("C:/Users/sebastian/desktop/selenium-3.0.1")
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'selenium-3.0.1' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x01EDEAF0>>
Traceback (most recent call last):
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
    self.stop()
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'

7 个答案:

答案 0 :(得分:33)

您可以在此处下载ChromeDriver: https://sites.google.com/a/chromium.org/chromedriver/downloads

然后您有多个options

  • 将其添加到您的系统path
  • 将其放在与python脚本相同的目录中
  • 直接通过executable_path

    指定地点
    driver = webdriver.Chrome(executable_path='C:/path/to/chromedriver.exe')
    

答案 1 :(得分:10)

Another way is download and unzip chromedriver and put 'chromedriver.exe' in C:\Python27\Scripts and then you need not to provide the path of driver, just

driver= webdriver.Chrome()

will work

答案 2 :(得分:5)

请勿在文件路径中包含“ .exe”。

例如:

from selenium import webdriver

driver = webdriver.Chrome(executable_path='path/to/folder/chromedriver')

答案 3 :(得分:3)

尝试:

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

答案 4 :(得分:2)

2020年的答案。以下代码解决了这个问题。许多硒新手似乎必须克服这一步骤。 安装chromedriver,并将其放在桌面上的文件夹中。还要确保将硒python项目放在与chrome驱动程序所在的文件夹中。

根据您的计算机更改USER_NAME和FOLDER。

对于Windows

driver = webdriver.Chrome(r"C:\Users\USER_NAME\Desktop\FOLDER\chromedriver")

对于Linux / Mac

driver = webdriver.Chrome("/home/USER_NAME/FOLDER/chromedriver")

答案 5 :(得分:0)

尝试一下:

pip install webdriver-manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

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

答案 6 :(得分:0)

另一种方法是下载并解压缩chromedriver并将'chromedriver.exe'放入C:\ Python27 \ Scripts中,然后您无需提供驱动程序的路径,

driver= webdriver.Chrome()

可以工作

可以证明这也适用于Python3.7。