javascript - NodeJS + PhantomJS + phantomJS-node + JQuery + click a link is not working -


i tried use phantomjs(v1.9.8) module (https://www.npmjs.com/package/phantom) node.js goal display current url , navigate programatically clicking next link using jquery. im unsuccessful in clicking next link. tried doing hard way via document no avail.

kindly point me right direction on how this.

code:

var phantom = require('phantom');  function scrape(keyword) {      phantom.create("", {}, function(ph) {          console.log("phantom bridge initiated");          ph.createpage(function(page) {              page.set("settings.javascriptenabled", true, function() {                 console.log("...enabling javascript");             });              page.set("settings.useragent", "mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, gecko) chrome/41.0.2227.0 safari/537.36", function() {                 console.log("...setting user agent");             });                       function traverse_page(page) {                 console.log('--- traverse_page ---');                  page.evaluate(function() {                      console.log("how many next found : " + $(".paginationnext a").length);                      if ($(".paginationnext a").length > 0) {                         $(".paginationnext a")[0].click();  // doesnt work                         // document.getelementsbyclassname('paginationnext')[0].getelementsbytagname('a')[0].click() // doesnt work                     }                       return document;                  }, function(result) {                      settimeout(function() {                         extract_values(page);                     }, 10000);                 })             }              function extract_values(page) {                 console.log("--- extract values ---");                  page.evaluate(function() {                     return {    "url": $(location).attr('href') };                 }, function(result) {                     console.log("url : " + result.url);                     traverse_page(page);                 });             }              page.open("http://search.infospace.com/search/web?q=thylacine&searchbtn=search", function(status) {                  page.set("onconsolemessage",function(msg) {                 if(msg.indexof("unsafe javascript") == -1){                     console.log(msg)}});                  page.includejs("http://code.jquery.com/jquery-2.1.4.min.js", function() {                     extract_values(page);                 })             });         });     }); } scrape(); 

result:

phantom bridge initiated ...enabling javascript ...setting user agent --- extract values --- url : http://search.infospace.com/search/web?q=thylacine&searchbtn=search --- traverse_page --- phantom stdout: typeerror: 'undefined' not function (evaluating '$(".paginationnext a")[0].click()')   phantom stdout:   phantomjs://webpage.evaluate():6   phantomjs://webpage.evaluate():11   phantomjs://webpage.evaluate():11  how many next found : 1 

duplicate of phantomjs; click element

you may want read http://phantomjs.org/api/webpage/method/send-event.html


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -