Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Phantomjs刮网页功能不工作_Javascript_Jquery_Dom_Phantomjs_Scrape - Fatal编程技术网

Javascript Phantomjs刮网页功能不工作

Javascript Phantomjs刮网页功能不工作,javascript,jquery,dom,phantomjs,scrape,Javascript,Jquery,Dom,Phantomjs,Scrape,我正在使用phantomjs学习如何刮取网页,到目前为止,我已经开发了以下代码。。我知道我可以连接到站点,但我根本无法从表中获取数据..我走对了吗 我的目标是从现场的表中获取数据。我也知道我需要使用includeJs或injectJs来等待表加载,否则我将删除一个空的html页面。我正试图把这些概念结合起来,但我已经被困了3天多了。请给我一些指导 var page = require('webpage').create(); console.log('Welcome to scraping...

我正在使用phantomjs学习如何刮取网页,到目前为止,我已经开发了以下代码。。我知道我可以连接到站点,但我根本无法从表中获取数据..我走对了吗

我的目标是从现场的表中获取数据。我也知道我需要使用includeJs或injectJs来等待表加载,否则我将删除一个空的html页面。我正试图把这些概念结合起来,但我已经被困了3天多了。请给我一些指导

var page = require('webpage').create();
console.log('Welcome to scraping...');

page.open('http://www.inc.com/inc5000/index.html', function(status) {
    page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
  if (status !== 'success') {
    console.log('Unable to access network');
  } else {
    var ua = page.evaluate(function() {
      var DATA = [];
      var res= document.getElementById((this).find('td')).eq(0).text();
      console.log(res); //**See output below for what is happening here**
        $('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('Got into func');  
      //return document.getElementById('myagent').textContent;
    });
    console.log('Got out of function');
    console.log(ua);
  }
  phantom.exit();
  });
  
});
我得到的输出是:

欢迎来到刮

ReferenceError:找不到变量:angular


TypeError:“null”不是对象(正在计算“document.getElementById(this.find('td')).eq'))

phantomjs://webpage.evaluate():3//这是什么意思

phantomjs://webpage.evaluate():20

phantomjs://webpage.evaluate():20

失灵

空的


奇怪<代码>页面。open在页面上阻塞,因为它试图在完成加载angular js之前使用angular js依赖项在页面上运行js。这一切都发生在它甚至到达
页面的回调之前。打开
,所以我不知道您将如何修复它。FWIW,这个页面是gzip的,我认为phantomjs有时候会遇到gzip页面的问题,idk如果相关的话,但是:这很有趣,那么什么是刮取这样一个页面的最好方法呢?上述代码是否可以改进以满足stretchr的需要?具有使用无头浏览器的选项。请注意,如果这有帮助,我将把它作为答案发布。是的,你能把它作为答案发布吗?@user3995789,你能解释更多关于欢呼选项的内容吗?它对我不起作用,尝试在我的pc上运行它,结果出现错误,将我指向代码的第27行(cheers.scrape(config)。然后…还有cheers.js的第71行,它只是一个“}”);“。。。不太确定这里发生了什么??