PhantomJS not returning results -
i'm testing out phantomjs , trying return startups listed on angel.co. decided go phantomjs since need paginate through front page clicking "next" @ bottom. right code not return results. i'm new phantomjs , have read through code examples guidance appreciated.
var page = require('webpage').create(); page.open('https://angel.co/startups', function(status) { if (status !== 'success') { console.log('unable access network'); } else { page.evaluate(function() { var list = document.queryselectorall('div.resume'); (var = 0; < list.length; i++){ console.log((i + 1) + ":" + list[i].innertext); } }); } phantom.exit(); });
by default, console messages evaluated on page not appear in phantomjs console.
when execute code under page.evaluate(...)
, code being executed in context of page. when have console.log((i + 1) + ":" + list[i].innertext);
, being logged in headless browser itself, rather in phantomjs.
if want console messages passed along phantomjs itself, use following after opening page:
page.onconsolemessage = function (msg) { console.log(msg); };
page.onconsolemessage
triggered whenever print console within page. callback, you're asking phantomjs echo message own standard output stream.
for reference, final code (this prints me):
var page = require('webpage').create(); page.open('https://angel.co/startups', function(status) { page.onconsolemessage = function (msg) { console.log(msg); }; if (status !== 'success') { console.log('unable access network'); } else { page.evaluate(function() { var list = document.queryselectorall('div.resume'); (var = 0; < list.length; i++){ console.log((i + 1) + ":" + list[i].innertext); } }); } phantom.exit(); });
Comments
Post a Comment