繁体   English   中英

尝试使用 selenium 打开网页但出现错误

[英]Trying to open a webpage using selenium but getting error

我写了这个简单的代码:

from selenium import webdriver
webdriver.Chrome().get('www.google.co.in')

但我收到此错误:

Traceback (most recent call last):
  File "C:\Users\user\PycharmProjects\WebAutomation\venv\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, 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\user\PycharmProjects\WebAutomation\venv\Automation.py", line 2, in <module>
    webdriver.Chrome().get('www.google.co.in')
 File "C:\Users\user\PycharmProjects\WebAutomation\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Users\user\PycharmProjects\WebAutomation\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__
    self.service.start()
  File "C:\Users\user\PycharmProjects\WebAutomation\venv\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://chromedriver.chromium.org/home

有人请帮助我。 我是初学者,请详细解释/指导(我不懂复杂的概念)

您将需要额外的 Selenium-Chrome-Driver.exe! 最后一行错误告诉你这一点。

selenium.common.exceptions.WebDriverException:消息:“chromedriver”可执行文件需要在 PATH 中。 请参阅https://chromedriver.chromium.org/home

驱动程序本身将从您的程序启动,并将保持您的程序与浏览器 chrome 本身之间的绑定。

driver.exe 可以很容易地放在 programm-startup-path 中(我建议在第一步中这样做)或放置在您想要的任何位置,但是您必须将 PATH 的特殊变量定义到 driver.exe。

您可以在此链接后面获取 driver.exe:

主页: https ://chromedriver.chromium.org/getting-started

下载页面: https ://chromedriver.chromium.org/downloads

请确保您的浏览器版本与驱动程序版本匹配。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM