For a project I have to make a web crawler. Seems to working fine up to a certain extent. The code is:
var Crawler = require("crawler");
var validUrl = require('valid-url');
var c = new Crawler({
maxConnections : 10,
callback : function (error, result, done) {
if(error){
console.log(error);
}else{
var $ = result.$;
var page = result.body;
var res = page.match(/pizza/i);
if(res && res.length > 0){
console.log($("title").text())
}
$("a").each(function(index,a){
if (validUrl.isUri(a.attribs.href)){
c.queue(a.attribs.href);
}
})
}
done();
}
});
c.queue('https://en.wikipedia.org/wiki/Pizza');
The error I'm getting is:
$("a").each(function(index,a){
^
TypeError: $ is not a function
Doesn't make sense because running it in console, I print out a decent list using the $ already and eventually it says not a function. Anyone know how to fix this?