我要讓我的代碼假冒refferer頭在解析系統(如谷歌分析),但它不工作。我添加了'var settings = {... // ...}'並添加'page.onLoadStarted = function(){page.customHeaders = {};'並加入 - 「page.open(...,設置...」,但它仍是公認就像在分析直接交通以下是代碼:僞造的Referer標頭在PhantomJS是行不通
var page = require('webpage').create();
var settings = {
headers: {
"Referer": "http://google.com"
}
};
var urls = ['http://china.com/','http://usa.com/','http://emirates.com/'];
var i = 0;
function OpenPage(){
setTimeout(function(){
page.onLoadStarted = function() {
page.customHeaders = {};
};
page.open(urls[i],settings, function(status) {
if (status == 'success') {
page.render('example' + i + '.png');
}
i++;
if(i <= urls.length - 1){
OpenPage();
}else{
phantom.exit();
}
});
},5000);
}
OpenPage();
我從這個問題https://stackoverflow.com/a/42468998/4999509得到這個代碼。和它的工作像一個編碼器魅力,尊重 - 閃光雷
您還可以添加以下內容以輸出請求頭,實際發送: page.onResourceRequested = function(requestData){ console.log('requestData:'+ JSON.stringify(requestData)); }; –
太糟糕了,我 - 我是新來的JS) –