【问题标题】:Apify - save JSON output to key-store-valueApify - 将 JSON 输出保存到 key-store-value
【发布时间】:2020-09-11 12:19:55
【问题描述】:

如何将此脚本的 JSON 输出保存到 Apify 中的 key-store-value 中? 当我运行脚本时,一切正常,数据集向我展示了每种类型的抓取数据,但键值存储/键仍然为空。对我来说有什么简单的命令吗? 这是我的演员代码:

const Apify = require('apify');

Apify.main(async () => {
    
    const metamorphInput = {
        "runMode": "DEVELOPMENT",
        "startUrls": [
            {
                "url": "https://mapa.covid.chat/table",
                "method": "GET"
            }
        ],
        "useRequestQueue": false,
        "keepUrlFragments": false,
        "pageFunction": // The function accepts a single argument: the "context" object.
        
        function pageFunction(context) {
        
            var $ = context.jQuery;
            const now = new Date();
            var towns = [];
            $("tr").each(function(data){
                towns.push({
                    city: ($(this).find("a").text()),
                    infected: ($(this).find(".text-right.infected").text().trim()),
                    todayNew: ($(this).find("sup").text().trim()),
                    lastFindCase: ($(this).find(".small-info").text()),
    
                });
            });
        
            return {towns}
        },
        "injectJQuery": true,
        "injectUnderscore": false,
        "proxyConfiguration": {
            "useApifyProxy": false
        },
        "proxyRotation": "RECOMMENDED",
        "useChrome": false,
        "useStealth": false,
        "ignoreSslErrors": false,
        "ignoreCorsAndCsp": false,
        "downloadMedia": true,
        "downloadCss": true,
        "waitUntil": [
            "networkidle2"
        ],
        "breakpointLocation": "NONE",
        "debugLog": false,
        "browserLog": false
    };
    
    // Now let's metamorph into actor apify/web-scraper using the created input.
    await Apify.metamorph('apify/web-scraper', metamorphInput);
    
});

【问题讨论】:

    标签: javascript json apify


    【解决方案1】:

    Web Scraper 的输出是一个数据集。但是您可以使用await context.setValue('OUTPUT', towns)pageFunction 存储到键值存储中。不知道为什么你也想变形。 https://apify.com/apify/web-scraper#setvaluekey-data-options-asyncfunction

    【讨论】:

    猜你喜欢
    • 2022-01-05
    • 2015-05-19
    • 2017-09-27
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    相关资源
    最近更新 更多