这是我的代码。
from selenium import webdriver
chrome_options = webdriver.ChromeOptions();
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']);
options = webdriver.Chrome(options=chrome_options)
options.get('https://www.google.com/')
images = options.find_elements_by_tag_name('img')
for image in images:
print(image.get_attribute('src'))
options.close()
当我运行这段代码时,我得到这个错误
**Traceback (most recent call last):
Python\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "Python\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "Python\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**
请检查我是否在代码中犯了任何错误,或者如果您了解此错误,请告诉我 谢谢
答案 0 :(得分:3)
声明驱动程序时,您需要将路径添加到chrome驱动程序中。
driver = webdriver.Chrome(options=chrome_options, executable_path=r"C:\path\to\chromedriver.exe")
答案 1 :(得分:2)
首先从https://link.jianshu.com/?t=https://sites.google.com/a/chromium.org/chromedriver/下载并安装浏览器驱动程序 解压缩并将其放在“ browserdriver”之类的目录中,并按如下所示更改代码:
from selenium import webdriver
browser = webdriver.Chrome(r"C:\browserdriver\chromedriver.exe")
browser.get("http://www.google.com")