【发布时间】:2014-10-11 15:46:00
【问题描述】:
这段代码在浏览器中运行,但在 Node.js(使用 JSDom + Crawler)中,我返回 undefined
$('div').find('.class').contents()[0].wholeText
你知道如何解决这个问题吗?
顺便说一句,当我尝试在 nodejs 中对其进行字符串化时,它返回错误Circular defintion
完整代码:
var Crawler = require("crawler").Crawler;
var data = {}
var c = new Crawler({
maxConnections: 10,
skipDuplicates: true,
// This will be called for each crawled page
callback: function(error, result, $) {
// $ is a jQuery instance scoped to the server-side DOM of the page
$("#link > ul > li > a").each(function(index, a) {
c.queue(a.href);
});
$("[id^=enfr]").each(function(index, a){
var fr = $(this).find('.FrWrd strong').html().replace(/<(?:.|\n)*?>/gm, '')
var to = $(this).find('.ToWrd').contents()[0]
console.log(fr + '\t\t\t\t\t' + to)
})
}
});
// Queue just one URL, with default callback
c.queue("http://www.wordreference.com/enfr/0");
【问题讨论】:
-
是
.queuejquery.queue()吗?谢谢 -
@guest271314 不。它是爬虫的一部分
-
没试过
node.js,crawler,jsdom。在没有[0]的情况下尝试了.contents()? , 或$(this).find('.ToWrd')[0].outerHTML?
标签: javascript jquery node.js web-crawler jsdom