您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
在Selenium中使用Ghostdriver抓取頁面
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2016/6/28 11:38:50 ] 推薦標簽:功能測試工具 Selenium

  緣起
  一位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()

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd