为该站点添加自定义标头似乎失败,在脚本 2 中,我刚刚注释掉了“接受”自定义标头并且它可以工作。有任何想法吗?Phantom Only 提供一个值“Syntax Error Parse Error”响应。此外,错误多次出现,就好像每一行都有错误一样。
脚本 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();
});