添加自定义标题似乎对此站点失败,在脚本2中,我刚刚注释掉了“Accept”自定义标题并且它可以正常工作。有任何想法吗? Phantom Only提供值“语法错误解析错误”响应。此错误也会多次显示,就好像每行都有错误一样。
脚本1 - 不起作用
var page = require('webpage').create();
var fs = require('fs');
page.settings.userAgent='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36';
page.onInitialized = function() {
page.customHeaders = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.8"
};
page.viewportSize = {width: 1280, height: 1024};
};
page.evaluate(function(){
});
page.open('http://www.gleanster.com/', function (status) {
if(status =='success'){
}
page.render('export.png');
fs.write('1.html', page.content, 'w');
phantom.exit();
});
脚本2 - 工作
var page = require('webpage').create();
var fs = require('fs');
page.settings.userAgent='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36';
page.onInitialized = function() {
page.customHeaders = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36",
// "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.8"
};
page.viewportSize = {width: 1280, height: 1024};
};
page.evaluate(function(){
});
page.open('http://www.gleanster.com/', function (status) {
if(status =='success'){
}
page.render('export.png');
fs.write('1.html', page.content, 'w');
phantom.exit();
});