使用Selenium模塊報錯的解決辦法FileNotFound,WebDriverException

    添加Chrome瀏覽器程序的目錄到系統Path變量中:

C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application ,使用pip3 install selenium安裝selenium模塊後,在jupyter notebook中運行示例程序:

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://www.baidu.cn')

 

【報錯信息】:

01-報錯信息1.png

02-報錯信息2.png

FileNotFoundError                         Traceback (most recent call last)

c:\users\catty\appdata\local\programs\python\python37\lib\site-packages\selenium\webdriver\common\service.py in start(self)

     75                                             stderr=self.log_file,

---> 76                                             stdin=PIPE)

     77         except TypeError:

 

FileNotFoundError: [WinError 2] 系統找不到指定的文件。
During handling of the above exception, another exception occurred:
WebDriverException                        Traceback (most recent call last)
<ipython-input-1-9c76fc9a65d6> in <module>
      1 from selenium import webdriver
      2
----> 3 browser = webdriver.Chrome()
      4 browser.get('http://www.baidu.cn')
      5
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home


 

【解決辦法】:

到網址:http://npm.taobao.org/mirrors/chromedriver/

下載與瀏覽器程序Chrome.exe相對應的版本的chromedriver.exe 程序,放到系統能夠找到的路徑中,比如:C:\Users\catty\AppData\Local\Programs\Python\Python37目錄下,再次在jupyter notebook中運行示例,不再報錯,能夠正常使用谷歌Chrome瀏覽器打開百度網站。

 

參考鏈接:

python Selenium2.0模塊使用中報錯的解決辦法

https://blog.csdn.net/limeilian10221017/article/details/70570056

 

chromedriver.exe下載

https://blog.csdn.net/morling05/article/details/81094151

 

Chromedriver.exe 下載地址

http://npm.taobao.org/mirrors/chromedriver/73.0.3683.68/

http://npm.taobao.org/mirrors/chromedriver/

Mirror index of http://chromedriver.storage.googleapis.com/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章