【发布时间】:2021-03-03 07:22:33
【问题描述】:
我正在尝试学习如何使用 selenium 和 python,并且我正在尝试关注此视频: https://www.youtube.com/watch?v=Xjv1sY630Uc&ab_channel=TechWithTim
这是我的代码:
from selenium import webdriver
PATH = "/Users/fuadhafiz/Documents\chromedriver.exec"
driver = webdriver.Chrome(PATH)
driver.get("https://stackoverflow.com")
但这就是终端上不断出现的内容(我正在使用 VS Code 并且在 mac 上)
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 "/Users/fuadhafiz/Documents/Python Projects/Selenium Automation /Web Scraping (1)/web_scraping_attempt.py"
fuadhafiz@Fuads-iMac Web Scraping (1) % /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 "/Users/fuadhafiz/Documents/Python Projects/Selenium Automation /Web Scraping (1)/web_scraping_attempt.py"
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/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: '/Users/fuadhafiz/Documents\\chromedriver.exec'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/fuadhafiz/Documents/Python Projects/Selenium Automation /Web Scraping (1)/web_scraping_attempt.py", line 4, in <module>
driver = webdriver.Chrome(PATH)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'Documents\chromedriver.exec' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
在“问题”部分
字符串中的反斜杠异常:'\c'。字符串常量可能缺少 r 前缀。
这是 chrome 驱动程序被保存的情况:
【问题讨论】:
标签: python macos selenium google-chrome selenium-chromedriver