使用 selenium webdriver 编译 python 代码时出错
Errors while compiling python code using selenium webdriver
我的代码是:
import time
from selenium import webdriver
driver = webdriver.Chrome('/Useres/arsenijgoj/PycharmProjects/pythonProject/chromedriver') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
错误是:
Traceback (most recent call last):
File "/Users/arsenijgoj/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1819, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Useres/arsenijgoj/PycharmProjects/pythonProject/chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/arsenijgoj/PycharmProjects/pythonProject/main.py", line 4, in <module>
driver = webdriver.Chrome('/Useres/arsenijgoj/PycharmProjects/pythonProject/chromedriver') # Optional argument, if not specified will search path.
File "/Users/arsenijgoj/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Users/arsenijgoj/PycharmProjects/pythonProject/venv/lib/python3.9/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
不知道该怎么办。
一切都已正确安装,chromedriver 的路径也是正确的(它甚至与项目位于同一目录中)。
使用 mac 空气 m1,PyCharm
有什么建议吗?
您的 chromedriver 路径有错字。 “用户”而不是“用户”。
改变
webdriver.Chrome('/Useres/arsenijgoj/PycharmProjects/pythonProject/chromedriver')
至
webdriver.Chrome('/Users/arsenijgoj/PycharmProjects/pythonProject/chromedriver')
我的代码是:
import time
from selenium import webdriver
driver = webdriver.Chrome('/Useres/arsenijgoj/PycharmProjects/pythonProject/chromedriver') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
错误是:
Traceback (most recent call last):
File "/Users/arsenijgoj/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1819, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Useres/arsenijgoj/PycharmProjects/pythonProject/chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/arsenijgoj/PycharmProjects/pythonProject/main.py", line 4, in <module>
driver = webdriver.Chrome('/Useres/arsenijgoj/PycharmProjects/pythonProject/chromedriver') # Optional argument, if not specified will search path.
File "/Users/arsenijgoj/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Users/arsenijgoj/PycharmProjects/pythonProject/venv/lib/python3.9/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
不知道该怎么办。 一切都已正确安装,chromedriver 的路径也是正确的(它甚至与项目位于同一目录中)。 使用 mac 空气 m1,PyCharm 有什么建议吗?
您的 chromedriver 路径有错字。 “用户”而不是“用户”。
改变
webdriver.Chrome('/Useres/arsenijgoj/PycharmProjects/pythonProject/chromedriver')
至
webdriver.Chrome('/Users/arsenijgoj/PycharmProjects/pythonProject/chromedriver')