首页 > Web开发 > 详细

How to scroll down with Phantomjs to load dynamic content

时间:2017-01-25 10:42:00      阅读:294      评论:0      收藏:0      [点我收藏+]
page.open(‘http://example.com/?q=houston‘, function () {

  // Checks for bottom div and scrolls down from time to time
  window.setInterval(function() {
      // Checks if there is a div with class=".has-more-items" 
      // (not sure if this is the best way of doing it)
      var count = page.content.match(/class=".has-more-items"/g);

      if(count === null) { // Didn‘t find
        page.evaluate(function() {
          // Scrolls to the bottom of page
          window.document.body.scrollTop = document.body.scrollHeight;
        });
      }
      else { // Found
        // Do what you want
        ...
        phantom.exit();
      }
  }, 500); // Number of milliseconds to wait between scrolls

});

How to scroll down with Phantomjs to load dynamic content

原文:http://www.cnblogs.com/c-x-a/p/6349081.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!