WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH
使用driver = webdriver.Chrome(options = chrome_options)时报错 :
WebDriverException: Message: ‘chromedriver‘ executable needs to be in PATH.
Please see https://sites.google.com/a/chromium.org/chromedriver/home
解决方法:
第1步
安装pip install selenium
第2步
安装pip install chromedriver
如果安装失败,更换pip下载源就可以了(附更换pip下载源方法链接)
https://blog.csdn.net/weixin_45798684/article/details/105337938
第3步
打开chrome 输入 “chrome://version/”来查看chrome版本,如下图:
然后访问此站
http://chromedriver.storage.googleapis.com/index.html
根据自己的版本号下载相应版本的chromedriver.exe
chromedriver与chrome的对应关系表如下图:
第4步
where python找到自己python.exe的位置:
把刚才下载解压好的chromedriver.exe放在该目录下:
第5步
再运行就没问题了
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
base_url = "http://www.baidu.com/"
driver = webdriver.Chrome(options = chrome_options)
driver.get(base_url + "/")
driver.find_element_by_id("kw").send_keys("Python程序设计")
driver.find_element_by_id("su").click()
driver.save_screenshot('screen.png')
driver.close()
如果出现:
DeprecationWarning: use options instead of chrome_options
解决方法在这里
https://blog.csdn.net/weixin_45798684/article/details/105337985