今天使用PhantomJS時,Selenium提示PhantomJS被標記不同意,我就蒙了。PhantomJS但是Headless瀏覽器中至關知名的一款,標記爲過期,表明着將在將來版本摒棄掉這個支持。因此仍是先棄用掉PhantomJS改用推薦的Headless Chrome比較好。python
Python 3.6.4 (default, Jan 5 2018, 02:35:40) [GCC 7.2.1 20171224] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from selenium import webdriver >>> driver=webdriver.PhantomJS() /usr/lib/python3.6/site-packages/selenium/webdriver/phantomjs/webdriver.py:49: 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 '
Headless模式是Chrome 59中的新特徵。
要使用Chrome須要安裝chromedriver。linux
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') driver = webdriver.Chrome(chrome_options=chrome_options) driver.get("https://cnblogs.com/")
其餘用法與PhantomJS基本相同。
更多資料請查看官方文檔。web