【问题标题】:How can I scrape a fully rendered web page with items loaded on scroll? [duplicate]如何使用滚动加载的项目抓取完全呈现的网页? [复制]
【发布时间】:2015-06-19 16:02:39
【问题描述】:

我要抓取“https://play.google.com/store/apps/category/EDUCATION/collection/topselling_paid”等Google PlayStore排名页面

当我使用浏览器查看页面时,它首先显示 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()
    });
});

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

【问题讨论】:

    标签: javascript web-crawler phantomjs


    【解决方案1】:

    您可以使用CasperJs。动态网页报废的好工具。

    CasperJs 是 PhantomJS 的导航脚本和测试实用程序

    例如你有点击事件:API Documentation

    【讨论】:

    • 推荐一个工具并不能解决问题。 CasperJS 并没有神奇地完成这项任务。也许你可以展示一下 如何 用 CasperJS 实现这一点?
    • 我已经设置了文档的例子来做到这一点
    猜你喜欢
    • 2015-09-09
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 2019-03-12
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    相关资源
    最近更新 更多