我正在尝试使用硒,并且不断收到错误消息:
Traceback (most recent call last):
File "C:\Users\jensa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\jensa\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\jensa\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "seleniumtest.py", line 5, in <module>
driver = webdriver.Chrome(executable_path=path)
File "C:\Users\jensa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\jensa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'webdriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我真的很困惑,因为没有什么在线帮助我。 chromedriver的文件夹位于PATH中。
我尝试将python文件放在与驱动程序相同的文件夹中,并且放在另一个文件夹中。
我尝试通过可执行文件路径指定位置。我尝试过在可执行文件路径中包含和不包含“ .exe”。没事。有人可以帮我解决这个问题。这是我的代码:
from selenium import webdriver
chromedriver = r"\C:\bin\chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("http://stackoverflow.com")
答案 0 :(得分:0)
您需要提供chrome驱动程序的二进制路径,请下载支持您浏览器版本的最新chrome驱动程序: 您可以下载Latest Chrome driver from here
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r"C:\bin\chromedriver.exe")
driver.maximize_window()
driver.get("url")
答案 1 :(得分:0)
如果它在PATH
中,则无需在您的代码中进行引用。
只需编写以下代码
from selenium import webdriver driver = webdriver.Chrome() driver.get("http://stackoverflow.com")