无法以编程方式在PhantomJS中滚动页面,完全在页面内..evaluate()

时间:2014-05-12 11:02:41

标签: javascript phantomjs

我希望能够将页面滚动到最后,基本上是为了加载更多内容。为此,我使用以下内容:

page.evaluate(function(){
  // Scrolls to the bottom of page
  window.document.body.scrollTop = document.body.scrollHeight;
})
var count = page.content.match(/(class=\".*?row.*?page.*?\".*?\<\/div\>)/g);

如果我以这种方式执行此操作,基本上在page.evaluate中设置scrollTop,并使用以下方法退出并检查加载的内容:page.content.match()

但我需要更多地与页面进行交互,所以我想在page.evaluate()内完全执行此操作。为此,我这样做:

page.evaluate(function(){
  // Scrolls to the bottom of page
  window.document.body.scrollTop = document.body.scrollHeight;

  delay = 5000
  // synchonously wait for 5 sec
  if (delay){
    var curr = new Date().getTime();
    delay += curr;
    while (curr < delay){
        curr = new Date().getTime();
    }
  }
  var count = $(selector).length;
})

我在这方面遇到问题,内容没有被加载。看到页面有page.render,但仍然没有解决方案。我可以使用以下命令看到使用页面控制台消息设置scrollTop属性:

page.onConsoleMessage = function(msg){
    console.log("PAGE> ",msg);
};

以下是我正在使用的测试网址: http://www.flipkart.com/all/disney~brand/pr?sid=all

0 个答案:

没有答案