如何正确地以无限滚动浏览网页

How to properly crawl through webpage with infinite scroll?

本文关键字:滚动 浏览 网页 无限 正确地      更新时间:2023-09-26

如何从具有无限滚动的网站中抓取数据?

我想做的是从Google Play商店获取所有数据(https://play.google.com/store/apps/category/GAME/collection/topselling_free?hl=en)。

我正在使用Apify(https://www.apify.com/)在Google Play商店中爬行;我想获得"游戏中的顶级免费"的所有链接,然后获得顶级游戏的所有标题和详细信息。

不幸的是,当用户滚动到页面底部时,页面会加载新数据,我不知道如何获取新数据。

这是我的页面功能:

function pageFunction(context) {
var $ = context.jQuery;
if (context.request.label === "DETAIL") {
    context.skipLinks();
    if($('.details-info .info-container .info-box-top .document-title .id-app-title').length >= 1) {
        return {
            title: $('.details-info .info-container .info-box-top .document-title .id-app-title').text(),
            publisher: $('.details-info .info-container .info-box-top .document-subtitles .primary').text(),
            genre: $('.details-info .info-container .info-box-top .document-subtitles .category').text(),
            rating: $('.details-wrapper .details-section .rating-box .score').text()
        };
    }
} else {
    context.skipOutput();
    $.post("https://play.google.com/store/apps/category/GAME/collection/topselling_free?hl=en&authuser=0");
}

}

我如何加载其他游戏并获取它们的链接,以便在游戏页面上获取它们的详细信息?

示例或示例代码将不胜感激。

在高级设置下,有一个名为"无限滚动高度"的选项可以从无限滚动中抓取内容。检查Apify文档