緣起
一位firefox抓取速度慢炬守,想加速毁枯,發(fā)現(xiàn)通過無界面的瀏覽器取抓取就可以快很多边败,因為不用進行瀏覽器頁面渲染袱衷,這個可是非常耗費時間的。這個理由夠了把笑窜。
安裝ghostdriver
因為ghostdriver已經(jīng)和phantomjs合二為一了致燥,所以直接安裝phantomjs(phantomis就是一個基于webkit的無界面瀏覽器,瀏覽器能干的他大多能干排截,就是不渲染出最后的網(wǎng)頁)
直接下載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()