版权声明:版权所有,转载请说明出处。 https://blog.csdn.net/matlab001/article/details/84060609
selenium配合ChromeDriver报错:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH;
代码如下:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
if __name__ == '__main__':
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(executable_path='./chromedriver', chrome_options=chrome_options)
driver.get("https://www.baidu.com")
print(driver.page_source)
driver.close()
研究之后发现原因如下:
executable_path='./chromedriver' 这个参数设定的是访问路径,可是我的路径下并没有chromedriver的程序,所以就报错了,关于这个问题的解决办法比较多,总起来也就是一条,那就是让程序搜寻的路径下能都发现这个driver就可以了。方法如下:
1.把chromedriver的exe程序放到某个path路径下,或者把程序所在路径加入到path路径,然后把executable_path='./chromedriver'这个参数去掉。
2.把chromedriver的exe放到executable_path这个参数对应的文件夹里面。