Javascript 如何使用cheerio JS从文本块中获取特定单词或数字
我想知道如何获得“id”之后的所有数字集:在JS中使用Cheerio的链接的每一行上: 例如:Javascript 如何使用cheerio JS从文本块中获取特定单词或数字,javascript,node.js,web-scraping,cheerio,Javascript,Node.js,Web Scraping,Cheerio,我想知道如何获得“id”之后的所有数字集:在JS中使用Cheerio的链接的每一行上: 例如: [{ "id": 19437838336128, "product_id": 2069464547456, "title": "3", "price": "110.00", "sku": "12757001&qu
[{
"id": 19437838336128,
"product_id": 2069464547456,
"title": "3",
"price": "110.00",
"sku": "12757001",
"position": 1,
"compare_at_price": "",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "3",
"option2": null,
"option3": null,
"created_at": "2020-07-13T07:24:00-04:00",
"updated_at": "2020-07-14T08:07:57-04:00",
"taxable": true,
"barcode": null,
"grams": 1361,
"image_id": null,
"weight": 3.0,
"weight_unit": "lb",
"tax_code": "PC040100",
"requires_shipping": true
}, {
"id": 19437838368896,
"product_id": 2069464547456,
"title": "3.5",
"price": "110.00",
"sku": "194496645118",
"position": 2,
"compare_at_price": "",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "3.5",
"option2": null,
"option3": null,
"created_at": "2020-07-13T07:24:00-04:00",
"updated_at": "2020-07-31T17:38:25-04:00",
"taxable": true,
"barcode": null,
"grams": 1361,
"image_id": null,
"weight": 3.0,
"weight_unit": "lb",
"tax_code": "PC040100",
"requires_shipping": true
},
因此,我希望能够在“id”之后获得两个变体:在每个项目的开头。(第一个是194378336128,第二个是19437838368896)您不需要为此进行DOM操作。您可以使用
fetch
(使用node.js)
你能链接polyfill吗:)@SalvatoreTimpani,就是在那里工作得很好!我让它记录了所有的变体,但是我如何将它们添加到列表中以随机选择变体?@SalvatoreTimpani这不是一个映射而不是一个数组吗?
fetch('https://kith.com/collections/mens-footwear/products/nkcw7297-100.json')
.then(res => res.json())
.then(data => {
let variantsIds = data.product.variants.map(p => p.id);
})
.catch(console.log)