Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.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 PhantjomJS重定向原始URL请求_Javascript_Html_Phantomjs_Uri - Fatal编程技术网

Javascript PhantjomJS重定向原始URL请求

Javascript PhantjomJS重定向原始URL请求,javascript,html,phantomjs,uri,Javascript,Html,Phantomjs,Uri,我正在尝试从一个URL获取html代码,该URL是该web上的一个特定搜索 问题是它会打印,这是执行空白搜索的结果。我做错了什么 命令如下: $ phantomjs get.js 'http://wzdig.pbc.gov.cn:8080/dig/ui/search.action?hl=zh-CN&sr=score+desc&q=%E9%93%81&rp=&advepq=%E9%93%81&advoq=&adveq=&ext=&ad

我正在尝试从一个URL获取html代码,该URL是该web上的一个特定搜索

问题是它会打印,这是执行空白搜索的结果。我做错了什么

命令如下:

$ phantomjs get.js 'http://wzdig.pbc.gov.cn:8080/dig/ui/search.action?hl=zh-CN&sr=score+desc&q=%E9%93%81&rp=&advepq=%E9%93%81&advoq=&adveq=&ext=&advtime=2&advrange=text%26title'
和get.js:

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

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

// Imitate a real browser
page.viewportSize = { width: 1440, height: 900 };
page.settings.userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36";

// Called every time a page is loaded
page.onLoadFinished = function(){

    // If the real page with search controls is loaded
    // then get page.content and exit
    var inputCount = page.evaluate(function(){
        return document.querySelectorAll("h3").length;
    });

    if(inputCount > 0) {
        console.log(page.content);
        phantom.exit();
    }

};

page.open(system.args[1]);

不是第一次尝试,但是可以获得您想要的页面。
以以下方式运行此脚本:
phantomjs--cookies文件=./xxx test.js>/dev/stdout

var page = require('webpage').create({viewportSize:{width: 1600,height: 900},
settings:{userAgent:'Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0',
javascriptEnabled:'true',
loadImages:'false'
}}), system = require('system');
page.onResourceError = function(resourceError) {
  console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
  console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
};
page.onConsoleMessage = function(msg, lineNum, sourceId) {
  console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.onResourceTimeout = function(request) {
    console.log('Response (#' + request.id + '): ' + JSON.stringify(request));
};

phantom.onError = function(msg, trace) {
  var msgStack = ['PHANTOM ERROR: ' + msg];
  if (trace && trace.length) {
    msgStack.push('TRACE:');
    trace.forEach(function(t) {
      msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
    });
  }
  console.error(msgStack.join('\n'));
  phantom.exit(1);
};

page.onError = function(msg, trace) {

  var msgStack = ['ERROR: ' + msg];

  if (trace && trace.length) {
    msgStack.push('TRACE:');
    trace.forEach(function(t) {
      msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
    });
  }

  console.error(msgStack.join('\n'));

};
page.onNavigationRequested = function(url, type, willNavigate, main) {
  console.log('Trying to navigate to: ' + url);
  console.log('Caused by: ' + type);
  console.log('Will actually navigate: ' + willNavigate);
  console.log('Sent from the page\'s main frame: ' + main);
}

page.open('http://wzdig.pbc.gov.cn:8080/dig/ui/search.action?hl=zh-CN&sr=score+desc&q=%E9%93%81&rp=&advepq=%E9%93%81&advoq=&adveq=&ext=&advtime=2&advrange=text%26title', function(){
//page.evaluate(function(){location='http://wzdig.pbc.gov.cn:8080/dig/ui/search.action?hl=zh-CN&sr=score+desc&q=%E9%93%81&rp=&advepq=%E9%93%81&advoq=&adveq=&ext=&advtime=2&advrange=text%26title'})
setTimeout(function(){
//    console.log(page.content);
page.render('t.png')
    phantom.exit();
},30000);// wait 30s
});

这个网站有点问题,有时候一切都很好,但有时候不行

这与
bash
tag?有什么关系,删除它@伊戈尔你什么意思?@伊戈尔?但是浏览器将其转换为%E9%93%81,这不应该起作用。我还有什么选择?谢谢@Igor。你认为可能是什么问题?我甚至无法在那里检测到一些东西,我有时会看到:
试图导航到:http://wzdig.pbc.gov.cn:8080/L2RpZy91aS9zZWFyY2guYWN0aW9u
和:
尝试导航到:http://wzdig.pbc.gov.cn:8080/dig/ui/search.action
而不是正确的URL,紧接着:
尝试导航到:http://wzdig.pbc.gov.cn:8080/dig/ui/search.action?hl=zh-CN&sr=score+desc&q=%E9%93%81&rp=&advepq=%E9%93%81&advoq=&adveq=&ext=&advtime=2&advrange=text%26title