在 Python 中使用Selenium 包进行数据分析时,遇到一个错误:
WebDriverException: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
解决方法如下:安装 selenium 的 python 包之后,还要安装chromedriver(浏览器 driver),我使用的是chrome,chrome浏览器驱动下载链接:https://sites.google.com/a/chromium.org/chromedriver/。然后复制chromedriver.exe文件到 Google Chrome 程序目录下,例如:C:\Program Files (x86)\Google\Chrome\Application。在Python 代码里创建 webdriver 对象时传递chromedriver.exe的路径,并且包含chromedriver文件名,例:
chromedriver = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver'
driver = webdriver.Chrome(chromedriver)