NodeJS x-ray web-scraper:如何关注链接并从子页面获取内容

所以我试图用node.js x-ray抓取框架来刮取一些内容。 虽然我可以从单个页面获取内容,但我无法理解如何关注链接并从一个子页面获取内容。

X射线githubconfiguration文件中有一个示例,但如果将代码更改为其他某个网站,则会返回空数据。

我简化了我的代码,并抓住了这个例子的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按照https://github.com/lapwinglabs/x-ray/issues/189