我正在尝试将硒用于python网络抓取程序,但是当我尝试运行该程序时,出现以下错误:
/usr/local/bin/python3 /Users/xxx/Documents/Python/hello.py
Traceback (most recent call last):
File "/library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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.8/lib/python3.8/subprocess.py",line 854,in __init__
self._execute_child(args,executable,preexec_fn,close_fds,line 1702,in _execute_child
raise child_exception_type(errno_num,err_msg,err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/xxx/Documents/Python/chromedriver.exe'
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "/Users/xxx/Documents/Python/hello.py",line 9,in <module>
wd = webdriver.Chrome(executable_path=DRIVER_PATH)
File "/library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py",line 73,in __init__
self.service.start()
File "/library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py",line 81,in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
这是python代码:
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
from selenium import webdriver
DRIVER_PATH = '/Users/xxx/Documents/Python/chromedriver.exe'
wd = webdriver.Chrome(executable_path=DRIVER_PATH)
我认为问题是我没有在DRIVER_PATH变量中正确指定文件路径,但是我不确定
我正在使用Mac