我正在抓取 Sainsbury's,这是我的起始 URL:https://www.sainsburys.co.uk/shop/gb/groceries/meat-fish/all-chicken-44?fromMegaNav=1#langId=44&storeId=10151&catalogId=10123&categoryId=310864&parent_category_rn=13343&top_category=13343&pageSize=36&orderBy=FAVOURITES_ONLY%7CSEQUENCING%7CTOP_SELLERS&searchTerm=&beginIndex=0&hideFilters=true
我希望在页面上显示类别、子类别和子类别以及每个项目的价格、标题和图像 src。
我当前的代码返回(以 JSON 格式)产品标题、价格和图像。它还返回我正在爬取的页面的类别、子类别和子子类别。我希望返回每个产品标题、价格和图片旁边的类别,但不确定如何设置循环来执行此操作。
function pageFunction(context) {
// called on every page the crawler visits, use it to extract data from it
var = context.jQuery; var result = []; (".article").each( function() {
result.push({
title : $(this).find(".productNameAndPromotions:eq(0) a:eq(0)").text(),
price : $(this).find(".pricePerUnit:eq(0)").text(),
image : $(this).find('img').attr('src'),
category : $(this).find('span:eq(1)').text(),
subcategory : $(this).find('span:eq(3)').text(),
subsubcategory : $(this).find('span:eq(5)').text(),
subsubsubcategory : $(this).find('span:eq(7)').text()
});
});
return result;}
这是我的代码返回的
我怎样才能做到这一点?