phantomjs介绍
生活随笔
收集整理的這篇文章主要介紹了
phantomjs介绍
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一. phantomjs定義
? ? 無界面的webkit引擎,它為我們提供了一個(gè)命名行的瀏覽器接口,可以幫助我們生成網(wǎng)頁的截圖以及抓取網(wǎng)頁內(nèi)容。
二.?phantomjs 下載及安裝
?
三.簡(jiǎn)單demo
? ?通過Phantomjs運(yùn)行簡(jiǎn)單的hello world demo如下
console.log('Hello, world!'); phantom.exit();
?
?
? ?通過Phantomjs抓取網(wǎng)頁的列子:
?
執(zhí)行如下命令:
#phantom page.js其生成的圖片結(jié)果如下:??
? ? ? ? ?
?
? ? ?例子3:loadspeed.js
? ? ??
var page = require("webpage").create(),system = require('system'),t, address;if(system.args.length===1) {console.log('usage: loadinspeed.js <some URL>');phantom.exit();}t = Date.now();address = system.args[1];console.log(address);page.open(address, function(status){console.log(status);if(status !== 'success'){console.log('faild to load the address');}else {t = Date.now() - t;console.log('loading time ' + t +' msec');}phantom.exit();});執(zhí)行結(jié)果如下
D:\demo>phantomjs loadspeed.js http://www.baidu.com http://www.baidu.com success loading time 513 msec?
通過evaluate()獲取頁面要素:
var page = require('webpage').create();page.open("http://phantomjs.org/quick-start.html", function(status) {var title = page.evaluate(function() {return document.title;});console.log('Page title is ' + title); });運(yùn)行結(jié)果
# hantomjs element.jsthe page title is Qucik Start | PhantomJS?
四. phantomjs與其他測(cè)試框剪的整合
? ??phantomjs本身不是一個(gè)測(cè)試框架,因此,需要借助其他的測(cè)試框剪來進(jìn)行測(cè)試運(yùn)行:常見的js測(cè)試框架已進(jìn)行運(yùn)行其列表如下:
? ??
| Buster.JS | built-in |
| Capybara | Poltergeist,?Terminus |
| Mocha | Chutzpah,?mocha-phantomjs |
| FuncUnit | built-in |
| Hiro | built-in |
| Karma?(née Testacular) | built-in |
| Jasmine | Chutzpah,?grunt-jasmine-runner,?guard-jasmine,?phantom-jasmine |
| JsTestDriver | js-test-driver-phantomjs |
| Laika | built-in |
| Robot Framework | phantomrobot |
| QUnit | built-in,?Chutzpah,?JS Test Runner,?Qlive,?QUnited |
| tapedeck | built-in |
| Testem | built-in |
| WebDriver | GhostDriver |
| wru | built-in |
| YUITest | Grover,?phantomjs-yuitest |
?
以上參考http://phantomjs.org
轉(zhuǎn)載于:https://www.cnblogs.com/dreamFromHere/p/3518296.html
總結(jié)
以上是生活随笔為你收集整理的phantomjs介绍的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ThreadGroup其实比Execut
- 下一篇: css制作漂亮彩带导航条菜单