phantomjs note

来源:互联网 发布:windows xp一键重装 编辑:程序博客网 时间:2024/05/29 19:24

useful likns:

phantomjs

cnblogs

Example1:

test.js:

console.log('Hello, world!');phantom.exit();

command:

phantomjs test.js

Example2:

test.js
var page = require('webpage').create();page.open('http://www.cnblogs.com/ziyunfei/archive/2012/09/28/2707356.html', function () {    page.render('google.png');    phantom.exit();});
command: 
phantomjs test.js
test_loadtime.js
var page = require('webpage').create(),    t, address;t = Date.now();address = 'http://google.com';page.open(address, function (status) {    if (status !== 'success') {        console.log('FAIL to load the address');    } else {        t = Date.now() - t;        console.log('Loading time ' + t + ' msec');    }    phantom.exit();});
command: 
phantomjs test_loadtime.js

Example3;

var page = require('webpage').create();var url = 'http://www.google.com';page.open(url, function (status) {    var title = page.evaluate(function () {        return document.title;    });    console.log('Page title is ' + title);});

Example4:

var page = require('webpage').create();var url = 'http://www.google.com';page.onResourceRequested = function (request) {    console.log('Request ' + JSON.stringify(request, undefined, 4));};page.onResourceReceived = function (response) {    console.log('Receive ' + JSON.stringify(response, undefined, 4));};page.open(url);





 

0 0
原创粉丝点击