简体   繁体   English

Headless Python Selenium 显示错误 'chromedriver' 可执行文件需要在 PATH 中

[英]Headless Python Selenium Shows Error 'chromedriver' executable needs to be in PATH

I am running a selenium script and I would like to run my code without opening the browser using chrome options.我正在运行一个 selenium 脚本,我想在不使用 chrome 选项打开浏览器的情况下运行我的代码。 I tried setting driver to PATH and then changing it to options=op but it showed the same error (The file path in my code is accurate).我尝试将驱动程序设置为 PATH 然后将其更改为 options=op 但它显示相同的错误(我的代码中的文件路径是准确的)。 I followed the second answer on this post and tried running chromedriver.exe in cmd (Not sure if this is relevant in but i saw this in another post and thought it could be of use).我遵循了这篇文章的第二个答案,并尝试在 cmd 中运行 chromedriver.exe(不确定这是否相关,但我在另一篇文章中看到了这个,并认为它可能有用)。 The snippet below was the output:下面的代码片段是 output:

c:\Program Files (x86)>chromedriver
Starting ChromeDriver 86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

Here is my code:这是我的代码:

from selenium import webdriver

PATH = "C:\Program Files (x86)\chromedriver.exe"
op = webdriver.ChromeOptions()
op.add_argument('headless')
# driver = webdriver.Chrome(PATH)
driver = webdriver.Chrome(options=op)

And here is the error I am receiving:这是我收到的错误:

Traceback (most recent call last):
  File "C:\Users\soodr\PythonFiles\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\soodr\PythonFiles\Lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\soodr\PythonFiles\Lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/soodr/PycharmProjects - Copy/pythonProject1/linkedenInfo.py", line 16, in <module>
    driver = webdriver.Chrome(options=op)
  File "C:\Users\soodr\PythonFiles\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\soodr\PythonFiles\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Is there something wrong about the way I am defining driver?我定义驱动程序的方式有问题吗?

your string is wrong.你的字符串是错误的。 if you wanna use \ in a string, do a raw string that is PATH = r"C:\Program Files (x86)\chromedriver.exe"如果您想在字符串中使用\ ,请执行原始字符串PATH = r"C:\Program Files (x86)\chromedriver.exe"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Selenium/Python 中出错 - chromedriver 可执行文件需要在 PATH 中 - Getting Error in Selenium/Python - chromedriver executable needs to be in PATH Python / Selenium - “chromedriver”可执行文件需要在路径中 - Python / Selenium - “chromedriver” executable needs to be in a PATH 'chromedriver' 可执行文件需要在 PATH 中 - Python - Selenium (MAC) - 'chromedriver' executable needs to be in PATH - Python - Selenium (MAC) selenium.common.exceptions.WebDriverException:消息:“chromedriver”可执行文件需要在无头 Chrome 的 PATH 错误中 - selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome 如何修复 Selenium 错误(Python) - 消息:“chromedriver.exe”可执行文件需要在 PATH 中 - How to fix Selenium Error (Python) - Message: 'chromedriver.exe' executable needs to be in PATH 带有 Mac 的 Python + 浏览器:错误 - &#39;chromedriver&#39; 可执行文件需要在 PATH 中 - Python + Browser with Mac: Error - 'chromedriver' executable needs to be in PATH WebDriverException:消息:“chromedriver”可执行文件需要在 PATH 中,同时通过 Selenium Chromedriver python 设置 UserAgent - WebDriverException: Message: 'chromedriver' executable needs to be in PATH while setting UserAgent through Selenium Chromedriver python &#39;chromedriver&#39; 可执行文件需要在 Python Django 的 PATH 中 - 'chromedriver' executable needs to be in PATH in Python Django chromedriver 的可执行文件需要在 PATH 中 - chromedriver' executable needs to be in PATH 错误消息:&#39;chromedriver&#39; 可执行文件需要是 PATH - Error Message: 'chromedriver' executable needs to be PATH
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM