缘起
一位firefox抓取速度慢,想加速,发现通过无界面的浏览器取抓取就可以快很多,因为不用进行浏览器页面渲染,这个可是非常耗费时间的。这个理由够了把。
安装ghostdriver
因为ghostdriver已经和phantomjs合二为一了,所以直接安装phantomjs(phantomis就是一个基于webkit的无界面浏览器,浏览器能干的他大多能干,就是不渲染出最后的网页)
直接下载phantomjs就好,由于各个平台的安装模式差异较大,就不多介绍了,百度一把就好。
linux or mac 备忘一句
#mac拥护请在地址下载,否则出错kill:9 #https://github.com/eugene1g/phantomjs/releases #软链接phantomjs ln -s /where/dir/phantomjs /usr/local/bin/phantomjs |
python 测试
#coding=utf-8 from selenium import webdriver import time import os br=webdriver.PhantomJS('phantomjs') baseurl="http://quote.eastmoney.com/" indexurl="stocklist.html" gourl="%s%s"%(baseurl,indexurl) br.get(gourl) print br.title time.sleep(5) br.quit() |
phantomjs 截图
#coding=utf-8 from selenium import webdriver import time import os br=webdriver.PhantomJS('phantomjs') baseurl="http://quote.eastmoney.com/" indexurl="stocklist.html" gourl="%s%s"%(baseurl,indexurl) br.get(gourl) br.save_screenshot('./股票列表.png') print "完成" br.quit() |