我有一台Windows64位计算机,我将chromedriver下载到了应该位于的确切位置,并且我的文件路径是:
'C:\Users\username\AppData\Local\Google\Chrome\Application\chrome.exe\chromedriver'
然后我编写了这段代码:
import selenium
from selenium import webdriver
driver=webdriver.Chrome('C:\Users\pushp\AppData\Local\Google\Chrome\Application\chrome.exe\chromedriver')
但是,我收到文件未找到错误以及此消息-
'Message: 'chromedriver' executable needs to be in PATH.'
我该如何解决?
答案 0 :(得分:1)
driver =webdriver.Chrome(r'C:\Users\pushp\AppData\Local\Google\Chrome\Application\chrome.exe\chromedriver.exe')
只需添加.exe
答案 1 :(得分:0)
像下面这样设置
import selenium
from selenium import webdriver
webdriver.Chrome(executable_path=r"C:\Users\pushp\AppData\Local\Google\Chrome\Application\chromedriver.exe")
或
webdriver.Chrome(executable_path="C:\\Users\\pushp\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
您还可以安装pip install webdriver-manager,然后运行以下代码,它将为您安装正确的网络驱动程序
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())