使用phantomJs我正在尝试获取2页的html内容。一页设置了userAgent,另一页没有。这是代码......
var url = "http://libertyplus.co.uk";
//var url = "http://facebook.com";
var page1 = require('webpage').create();
var page2 = require('webpage').create();
page1.settings.javascriptEnabled = true;
page1.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
page2.settings.javascriptEnabled = true;
var content = new Array;
page1.open(url, function(status){
if(status == 'success'){
content.push(page1.content);
}
});
page2.open(url, function(status){
if(status == 'success'){
content.push(page2.content);
}
});
setTimeout(function(){
console.log(JSON.stringify(content));
phantom.exit();
}, 2500);
当url为http://www.libertyplus.co.uk
并且我按预期获得两个内容时,这非常有效,但是当我将网址更改为http://facebook.com
时,我得到一个空数组。