When using the npm crawler to crawl links, I get the error:
C:\Users\ryani\Desktop\JavaScript\crawler\crawler.js:15
$('a').each(function(index, value) {
^
TypeError: Cannot read property 'each' of undefined
I've tried setting timeouts and various debugging techniques... I'm not sure why it is getting undefined; when I put the code in a tag on an html page, it works fine.
crawler.js:
var Crawler = require("crawler");
var c = new Crawler({
"maxConnections":10,
"callback":function(error, res, $) {
if (error) {
console.log("error");
console.log(error);
} else {
$('a').each(function(index, value) {
console.log($(this).attr('href'));
//c.queue(href)
});
}
}
});
c.queue('http://www.google.com');
via Ryan Walker
No comments:
Post a Comment