This code does work in the browser, but in Node.js (using JSDom + Crawler), i returns undefined
$('div').find('.class').contents()[0].wholeText
Any idea on how to solve this?
BTW, when I try to stringify this in nodejs, it returns the error Circular defintion
The full code:
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");
OK Finally I resolved it by using the "stock" DOM library:
var to = $(this).find('.ToWrd').get(0).firstChild.nodeValue