不完整地加载网页Phantomjs

时间:2018-06-13 01:49:38

标签: login resources phantomjs loading webpage

我在捕获和加载网页时遇到问题: https://myaccount.nytimes.com/auth/login

缺少用户名和密码字段以及提交按钮。可能是什么原因?感谢

正如您所看到的,下面列出的代码将逐个等待加载每个和所有资源。

我没有编写代码,但它很好并经过许多测试。原文可以在这里找到: https://gist.github.com/cjoudrey/1341747 (给写作者的所有信用。)

    var resourceWait  = 3000,
    maxRenderWait = 30000,
   url = 'https://myaccount.nytimes.com/auth/login'; //'https://twitter.com/#!/nodejs';

   var page          = require('webpage').create(),
   count         = 0,
   forcedRenderTimeout,
   renderTimeout;

   page.viewportSize = { width: 1280, height : 1024 };

   function doRender() {
      page.render('twitter.png');
      phantom.exit();
   }

   page.onResourceRequested = function (req) {
      count += 1;
      console.log('> ' + req.id + ' - ' + req.url);
      clearTimeout(renderTimeout);
   };

   page.onResourceReceived = function (res) {
     if (!res.stage || res.stage === 'end') {
        count -= 1;
        console.log(res.id + ' ' + res.status + ' - ' + res.url);
        if (count === 0) {
           renderTimeout = setTimeout(doRender, resourceWait);
        }
     }
   };

  page.open(url, function (status) {
     if (status !== "success") {
        console.log('Unable to load url');
        phantom.exit();
     } else {
        forcedRenderTimeout = setTimeout(function () {
           console.log(count);
           doRender();
        }, maxRenderWait);
     }
  });

0 个答案:

没有答案