javascript - Function is not being executed when split into multiple functions -
javascript - Function is not being executed when split into multiple functions -
i writing script using casperjs , have function:
extractor.prototype.get_links = function() { var links = document.queryselectorall('p.title a'); homecoming array.prototype.map.call(links, function(element) { homecoming element.getattribute('href'); }); };
which works fine , desired result. when seek create new function , phone call it, so:
function test_this() { var links = document.queryselectorall('p.title a'); homecoming array.prototype.map.call(links, function(element) { homecoming element.getattribute('href'); }); }; extractor.prototype.get_links = function() { test_this(); };
this casper.start method:
casper.start(webpage, function() { var extractor = new extractor(); links = links.concat(this.evaluate(extractor.get_links)); });
it seems function not beingness called, , not desired result. new casperjs , javascript, , cannot seem figure out doing wrong.
casper.evaluate
sandboxed. interface page context. variables defined outside of page context not accessible outside.
in case test_this
defined outside of page context. define through separate evaluate
if want separation:
casper.start(webpage, function() { this.evaluate(function(){ function test_this() { var links = document.queryselectorall('p.title a'); homecoming array.prototype.map.call(links, function(element) { homecoming element.getattribute('href'); }); } }); var extractor = new extractor(); links = links.concat(this.evaluate(extractor.get_links)); });
javascript phantomjs casperjs
Comments
Post a Comment