phantomjs not reaching function

試著忘記壹切 提交于 2019-12-11 09:38:51

问题


following on from this , I have rewritten my script but am unable to reach the function where I am performing the scrape of data. As a result my object is null.

How can I ensure I reach the function? How can I populate the object? (note I the object and the way to populate it is based on discussion from an earlier post, but please let me know if I am making any error here in the script below)

Error Output:

ReferenceError: cant find variable: angular (not sure what this means...am ignoring for now) http://stage.inc.com/js/Inc5000ListApp.js?UPDATE1:2

http://www.inc.com/inc5000/index.html:2485

Read About the Companies in the Inc. 5000 | Inc.com (this is the title, which am printing)

null (the object is null and I don't know why??..well actually the function is not being accessed, but how I can correct this...)

Code

var webPage = require('webpage');
var page = webPage.create();

page.open('http://www.inc.com/inc5000/index.html', function(status) {

  var title = page.evaluate(function(s) {
    return document.querySelector(s).innerText;
  }, 'title');

  console.log(title);
  page.injectJs('http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js');
  var dataObj= page.evaluate(function() { 
    console.log('Reached scrapeData');
    var DATA = [];
        $('tr.ng-scope').each(function(){
            var $tds = $(this).find('td');
            DATA.push({
                rank:     $tds.eq(0).text(),
                company:  $tds.eq(1).text(),
                growth:   $tds.eq(2).text(),
                revenue:  $tds.eq(3).text(),
                industry: $tds.eq(4).text()
            });
        });

        console.log(DATA);
    });
    console.log(dataObj);
  phantom.exit();

});

来源:https://stackoverflow.com/questions/25706972/phantomjs-not-reaching-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!