我试图在python 刮刀器中使用selenium,但是当我试图运行该程序时,会出现以下错误:
/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,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", 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
发布于 2019-11-08 20:27:38
您需要更新DRIVER_PATH以包括根目录(通常为C:\ )。
DRIVER_PATH = 'C:/Users/xxx/Documents/Python/chromedriver.exe'或者,您可以按照本教程将包含chromedriver.exe文件夹(通常是chromedriver_win32文件夹)的路径添加到Path环境变量中:
https://docs.telerik.com/teststudio/features/test-runners/add-path-environment-variables
发布于 2019-11-08 20:20:22
我会尝试这个(只是添加'r'):
wd = webdriver.Chrome(executable_path=r'/Users/xxx/Documents/Python/chromedriver.exe')如果你认为是文件,那就去检查一下:
import os.path
os.path.exists(DRIVER_PATH)此外,美汤是使用威尔与urllib2 https://www.pythonforbeginners.com/beautifulsoup/beautifulsoup-4-python
import urllib2
url = "https://www.URL.com"
content = urllib2.urlopen(url).read()
soup = BeautifulSoup(content)发布于 2020-08-03 14:33:02
你在文件的名字上弄错了。
"chomedriver.exe“是用于windows的。
如果对Mac使用macOS和chromedriver,那么文件名应该是"chomedriver“,而不是".exe”。
我也有同样的问题,但这解决了它。
https://stackoverflow.com/questions/58773072
复制相似问题