Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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 NodeJS x-ray网络刮板:如何跟踪链接并从子页面获取内容_Javascript_Node.js_Web Scraping_Web Crawler_X Ray - Fatal编程技术网

Javascript NodeJS x-ray网络刮板:如何跟踪链接并从子页面获取内容

Javascript NodeJS x-ray网络刮板:如何跟踪链接并从子页面获取内容,javascript,node.js,web-scraping,web-crawler,x-ray,Javascript,Node.js,Web Scraping,Web Crawler,X Ray,因此,我尝试使用node.js x-ray刮片框架来刮片一些内容。虽然我可以从一个页面上获取内容,但我无法了解如何通过链接一下子从一个子页面获取内容 x-ray github配置文件中有一个示例,但如果我将代码更改到其他站点,它将返回空数据 我简化了我的代码,并使其能够抓取此示例的SO问题。 以下工作很好: var Xray = require('x-ray'); var x = Xray(); x('http://stackoverflow.com/questions/9202531/min

因此,我尝试使用node.js x-ray刮片框架来刮片一些内容。虽然我可以从一个页面上获取内容,但我无法了解如何通过链接一下子从一个子页面获取内容

x-ray github配置文件中有一个示例,但如果我将代码更改到其他站点,它将返回空数据

我简化了我的代码,并使其能够抓取此示例的SO问题。

以下工作很好:

var Xray = require('x-ray');
var x = Xray();

x('http://stackoverflow.com/questions/9202531/minimizing-nexpectation-for-a-custom-distribution-in-mathematica', '#content', [{

  title: '#question-header h1',
  question: '.question .post-text'

}])
(function(err, obj) {

  console.log(err);
  console.log(obj);

})
这也适用于:

var Xray = require('x-ray');
var x = Xray();

x('http://stackoverflow.com/questions', '#questions .question-summary .summary', [{

  title: 'h3',
  question: x('h3 a@href', '#content .question .post-text'),

}])
(function(err, obj) {

  console.log(err);
  console.log(obj);

})
但这给了我一个空洞的细节结果,我无法找出问题所在:

var Xray = require('x-ray');
var x = Xray();

x('http://stackoverflow.com/questions', '#questions .question-summary .summary', [{

  title: 'h3',
  link: 'h3 a@href',
  details: x('h3 a@href', '#content', [{
    title: 'h1',
    question: '.question .post-text',
  }])

}])
(function(err, obj) {

  console.log(err);
  console.log(obj);

})

我想让我的爬行器抓取包含列出问题的页面,然后按照每个问题的链接检索其他信息。

因此,在一些帮助下,我找到了问题所在。我张贴这个答案,以防其他人可能有同样的问题

工作示例:

var Xray = require('x-ray');
var x = Xray();

x('http://stackoverflow.com/questions', '#questions .question-summary .summary', [{

  title: 'h3',
  link: 'h3 a@href',
  details: x('h3 a@href', {
    title: 'h1',
    question: '.question .post-text',
  })

}])
(function(err, obj) {

  console.log(err);
  console.log(obj);

})

版本2.0.2确实有效。。github中当前有一个问题需要解决llowhttps://github.com/lapwinglabs/x-ray/issues/189

嗯,您确定粘贴了正确的代码吗?还是不能让我的工作。做完全相同的事情,有你在问题中描述的3个症状。你能提供你从这个查询中得到的结果吗?看起来这是其他人的问题。所以我想知道你是怎么让这东西工作的?如果你只是复制粘贴上面的代码,它能工作吗?我会在回家后再试一次,并将结果告知您。我尝试运行您的代码,但未返回详细信息属性。它还在为你工作吗?您知道这种嵌套爬网行为是否已被弃用吗?您可以在此处找到与此问题相关的一些答案:[x射线抓取辅助URL相关问题]()