Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PhantomJS CustomHeader导致错误_Javascript_Phantomjs_Custom Headers - Fatal编程技术网

Javascript PhantomJS CustomHeader导致错误

Javascript PhantomJS CustomHeader导致错误,javascript,phantomjs,custom-headers,Javascript,Phantomjs,Custom Headers,对于这个站点,添加一个自定义标题似乎失败了,在脚本2中,我刚刚注释掉了“接受”自定义标题,它可以正常工作。有什么想法吗?Phantom仅提供值“语法错误解析错误”响应。此外,错误会显示多次,就好像每行都有错误一样 脚本1-不起作用 var page = require('webpage').create(); var fs = require('fs'); page.settings.userAgent='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWeb

对于这个站点,添加一个自定义标题似乎失败了,在脚本2中,我刚刚注释掉了“接受”自定义标题,它可以正常工作。有什么想法吗?Phantom仅提供值“语法错误解析错误”响应。此外,错误会显示多次,就好像每行都有错误一样

脚本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();
});

这是一个相当复杂的接受头,所以您尝试过其他更简单的吗?例如,尝试一下“接受”:“text/html”,然后从那里开始工作,直到它中断。(我想知道
+
=
是否需要转义,但据我所知,HTTP头值中允许使用任何可打印的ASCII字符。)