Mac-Python 零基础爬虫学习笔记(2):phantomjs不再 headless Firefox/Chrome

phantomjs是一个功能完善的“无头“浏览器,并非一个python库,所以它不需要想python的其他库一样安装,也不能用pip安装。

但是‘Selenium support for PhantomJS has been deprecated, please use headless’提示不支持PhantomJs,请使用headless模式。

使用headless模式之后,就不会有GUI了。

from selenium import webdriver
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

options = webdriver.FirefoxOptions()
options.add_argument('-headless') 
dirver = webdriver.Firefox(executable_path= '/Users/Mike/Downloads/geckodriver',firefox_options=options)
dirver.get('https://music.douban.com/')
for i in dirver.find_elements_by_css_selector('.new-albums .album-title'):
    print i.text

猜你喜欢

转载自blog.csdn.net/milkbusy/article/details/81585459