新版的 selenium已經放棄PhantomJS改用Chorme headless


新版的 selenium已經放棄PhantomJS改用Chorme headless

 

使用pip show selenium顯示默認安裝的是3.1.3版本
目前使用新版selenium調用PhantomJS是會報這樣的錯: UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless

如果還想繼續用PhantomJS的話只能使用舊版的selenium,卸載之后重新pip install selenium==2.48.0安裝成功。
但其實更好的選擇,我們可以使用firefox或chrome的headlesss模式,無需重裝selenium
只需要添加以下代碼:

from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu')#上面三行代碼就是為了將Chrome不彈出界面,實現無界面爬取 browser = webdriver.Chrome(chrome_options=chrome_options) 

也能完美實現無界面爬蟲


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM