如何解决FileNotFoundError尝试使用Selenium和WebDriver自动执行对Google表单的响应
我正在尝试自动执行对Google表单的一些响应(我正在尝试基于此模型执行某些操作:youtu.be/BvU7qfdrqjc(25秒视频);该视频显示了更多。 jl)。我正在测试此代码,发生错误:
代码:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
print(driver.title())
print(driver.current_url())
我在Windows命令提示符中键入的内容:
C:\Users\localuser>python C:\Users\localuser\Desktop\webdriver_test.py
C:\ Users \ localuser \ Desktop \ webdriver_test.py是带有上述代码的注释
返回的错误消息:
File "C:\Python\lib\site-packages\selenium\webdriver\common\service.py",line 72,in start
self.process = subprocess.Popen(cmd,env=self.env,File "C:\Python\lib\subprocess.py",line 854,in __init__
self._execute_child(args,executable,preexec_fn,close_fds,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\localuser\Desktop\webdriver_test.py",line 3,in <module>
driver = webdriver.Chrome()
File "C:\Python\lib\site-packages\selenium\webdriver\chrome\webdriver.py",line 73,in __init__
self.service.start()
File "C:\Python\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'''
解决方法
Step1 :检出您所使用的chrome版本。转到Chrome设置,然后点击关于Chrome 。检查版本。
第二步 :转到ChromeDriver Downlaod
安装与您使用的chrome版本匹配的相同驱动程序。
Step3 :然后将可执行文件解压缩到python文件的目录中。然后尝试再次执行。
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
print(driver.title)
print(driver.current_url)
此外,在调用以提取诸如“ title”和“ current_url”之类的属性后,您也不需要括号,因为它是一个字符串,并且您试图将其用作函数。查看最后两行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。