如何将此脚本的JSON输出保存到Apify中的key-store-value?当我运行脚本时,一切正常,数据集显示了每种类型的抓取数据,但是key-value-store/Keys仍然是空的。有什么简单的命令可以帮我做到这一点吗?下面是我的Actor代码:
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);
});发布于 2020-09-11 20:41:03
Web Scraper的输出是一个数据集。但是您可以使用await context.setValue('OUTPUT', towns)从pageFunction存储到键值存储中。不知道为什么你也想变形。https://apify.com/apify/web-scraper#setvaluekey-data-options-asyncfunction
https://stackoverflow.com/questions/63846979
复制相似问题