【发布时间】: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