gpt4 book ai didi

javascript - 如何抓取滚动加载项目的完全呈现的网页?

转载 作者:行者123 更新时间:2023-12-04 01:07:25 31 4
gpt4 key购买 nike

<分区>

我想抓取 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()
});
});

如何抓取完全呈现的页面?

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com