伪造的Referer标头在PhantomJS是不起作用(Faking the Referer Hea

2019-09-25 16:56发布

我要让我的代码假冒refferer头在解析系统(如谷歌分析),但它不工作。 我有加 '变量​​设置= {... // ...}',添加 'page.onLoadStarted =函数(){page.customHeaders = {};' 并加入 - “page.open(...,设置...”,但它仍是公认就像在分析直接交通以下是代码:。

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和它的工作就像一个魅力,尊重编码器-闪光雷!

Answer 1:

尝试这个:

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

page.onLoadStarted = function() {
    page.customHeaders = {};
};

var urls = ['http://china.com/','http://usa.com/','http://emirates.com/'];
var i = 0;

function OpenPage(){
    setTimeout(function(){
        page.customHeaders = {
            "Referer": "https://google.com"
        };
        page.open(urls[i], function(status) {
            if (status == 'success') {
                    page.render('example' + i + '.png');
            }
            i++;
            if(i <= urls.length - 1){ 
                OpenPage();
            }else{
               phantom.exit();
            }
        });
    },5000);
}    
OpenPage();


Answer 2:

这适用于谷歌分析,

var settings = {
    headers: {
        "Referer": "http://www.google.com/"
    }
};

page.open(urlToVisit, settings, function (status) {
    ...
}

基本上,你需要让你自定义的引用者可使用上page.open第二个参数()在为谷歌Analytics(分析)代码的页面上下文功能,能够阅读它



文章来源: Faking the Referer Header in PhantomJS is doesn't work
标签: phantomjs