javascript - CasperJS doesn't find jQuery -
this question has answer here:
- pass javascript function parameter 12 answers
i'm using jquery selectors casper.js scraping. understand it's necessary place jquery calls inside casper.evaluate()
.
the problem in last of these following 3 functions, referenceerror: can't find variable: $
raised. first 2 work absolutely fine.
// on main page, scrape links sub-pages. function getlinks() { var links = $('li.ds-artifact-item a'); return array.prototype.map.call(links, function(e) { return e.getattribute('href'); }); } // on main page, scrape sub-pages' titles. function gettitles() { var titles = $('li.ds-artifact-item a'); return array.prototype.map.call(titles, function(e) { return e.innerhtml; }); } // on sub-page, scrape document description. function getdescription(){ var descriptions = $('td.label-cell:contains(date)'); return array.prototype.map.call(descriptions, function(e) { return e.innerhtml; }); }
here's rest of script, unimportant details obscured. note anothervalidpage
valid url returns http 200 (success).
var links = []; var titles = []; var descriptions = []; casper.start(validpage, function() { links = this.evaluate(getlinks); titles = this.evaluate(gettitles); }); casper.then(function() { // echo results this.echo(links.length + ' links found:'); this.echo(' - ' + links.join('\n - ')); this.echo(titles.length + ' titles found:'); this.echo(' - ' + titles.join('\n - ')); }); casper.thenopen(anothervalidpage, function(){}); casper.then(function(){ // call problematic one. descriptions = this.evaluate(getdescription()); this.echo(descriptions.length + ' descriptions found:'); this.echo(' - ' + descriptions.join('\n - ')); }); casper.run();
i found solution: instead of calling this.evaluate(getdescription())
had call this.evaluate(getdescription)
, since guess executing function instead of passing argument, whoops.
Comments
Post a Comment