<分区>
我想抓取 Google PlayStore 排名页面,例如“https://play.google.com/store/apps/category/EDUCATION/collection/topselling_paid”
当我使用浏览器查看页面时,它首先显示 60 个应用程序,然后通过鼠标滚动并单击“显示更多”按钮显示最多 540 个应用程序。
我认为当创建“鼠标滚动”、“单击按钮”等事件时,页面已完全呈现。
问题是我不知道如何在没有浏览器的情况下生成这些事件,因此我只能抓取未完全呈现且仅包含 60 个应用程序的页面。
我用 PhantomJS 尝试了下面的代码,但根本没有用。
var page = require('webpage').create(),
system = require('system'),
url;
url = system.args[1];
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open(url, function() {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
page.evaluate(function() {
//Shows ranking up to 60th.
console.log($("a.title").text());
//Tried scroll mouse. However, cannot render the page.
for(i=0; i<150; i++){
console.log(document.body.scrollTop)
window.scrollTo(0, document.body.scrollHeight);
console.log(document.body.scrollTop)
window.scrollTo(0, 0);
}
//Expect to show ranking up to 540th.
console.log($("a.title").text());
});
phantom.exit()
});
});
如何抓取完全呈现的页面?