phantomjs not waiting for “full” page load

前端 未结 14 1251
南旧
南旧 2020-11-22 13:48

I\'m using PhantomJS v1.4.1 to load some web pages. I don\'t have access to their server-side, I just getting links pointing to them. I\'m using obsolete version of Phantom

14条回答
  •  天命终不由人
    2020-11-22 14:45

    This the code I use:

    var system = require('system');
    var page = require('webpage').create();
    
    page.open('http://....', function(){
          console.log(page.content);
          var k = 0;
    
          var loop = setInterval(function(){
              var qrcode = page.evaluate(function(s) {
                 return document.querySelector(s).src;
              }, '.qrcode img');
    
              k++;
              if (qrcode){
                 console.log('dataURI:', qrcode);
                 clearInterval(loop);
                 phantom.exit();
              }
    
              if (k === 50) phantom.exit(); // 10 sec timeout
          }, 200);
      });
    

    Basically given the fact you're supposed to know that the page is full downloaded when a given element appears on the DOM. So the script is going to wait until this happens.

提交回复
热议问题