使用Phantomjs访问网页并截图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| var page = require('webpage').create();
page.onResourceRequested = function(request) { console.log('Request ' + JSON.stringify(request, undefined, 4)); console.log( '---------------------------------------------------------------------' ); }; page.onResourceReceived = function(response) { console.log('Receive ' + JSON.stringify(response, undefined, 4)); console.log( '---------------------------------------------------------------------' ); };
page.open('https://www.baidu.com', function(status) { console.log("Status: " + status); if(status === "success") { page.render('example.png'); } phantom.exit(); });
|
example.png
Phantomjs已经接近废弃,如今推荐使用google的headless技术。