phantomjs 抓取动态网页

新手上路,请多包涵

为什么phantomjs 无法抓取 网页 例如 动态动态网页 http://m.ctrip.com/webapp/tou... 上面的js内部内容:

code:

var page = require('webpage').create();
system = require('system')

if (system.args.length === 1) {

phantom.exit();

} else {
var address = system.args[1];
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0';
page.settings.javascriptEnabled = true;
page.settings.referer = 'http://m.ctrip.com/webapp/tou...';

page.onResourceRequested = function (req) {

//console.log('requested: ' + JSON.stringify(req, undefined, 4));

// console.log(JSON.parse(JSON.stringify(req, undefined, 4)).url);
};
page.open(address, function(status){

page.onConsoleMessage = function (msg) { console.log(msg); };
if (status !== 'success') {
    phantom.exit();
}
var sc = page.evaluate(function(){

    return document.body.innerHTML;
    //return document.documentElement.innerHTML;
});
window.setTimeout(function(){
    console.log(sc);
    console.log('----');
    console.log(page.content);
    phantom.exit();
},1000);

});

阅读 4.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进