ソースを参照

Add missing data from AR scraping config. TG-4

Tati 7 年 前
コミット
01b3a4249a
1 ファイル変更9 行追加4 行削除
  1. 9 4
      ktchn/src/recipes/scrape/sources/all-recipes.ts

+ 9 - 4
ktchn/src/recipes/scrape/sources/all-recipes.ts

@@ -7,6 +7,8 @@ const SELECTORS = {
   SERVINGS: 'meta#metaRecipeServings',
   INGREDIENTS: 'div#polaris-app',
   INSTRUCTIONS: 'li.step',
+  SUMMARY: 'meta#metaDescription',
+  TAGS: 'meta[itemprop="recipeCategory"]',
 }
 
 function getRecipeName($: CheerioSelector): string {
@@ -52,11 +54,11 @@ function getIngredients($: CheerioSelector): ComposedIngredients[] {
 }
 
 function getInstructions($: CheerioSelector): string[] {
-  const rawData = $(SELECTORS.INSTRUCTIONS).toArray().map(element => $(element).text().trim());
-  console.log(JSON.stringify(rawData));
-  return rawData;
+  return $(SELECTORS.INSTRUCTIONS).toArray().map(element => $(element).text().trim());
 }
 
+const getTextList = (SELECTOR: string) => ($: CheerioSelector): string[] => $(SELECTOR).map((i, e) => $(e).text().trim()).get()
+
 const AR_CONFIG = {
   name: 'All Recipes',
   domain: 'allrecipes',
@@ -66,7 +68,10 @@ const AR_CONFIG = {
     getAuthorData($),
     getRecipeDetails($),
     getIngredients($),
-    getInstructions($),
+    getTextList(SELECTORS.INSTRUCTIONS)($),
+    $(SELECTORS.TAGS).map((i, e) => $(e).attr('content')).get(),
+    [],
+    $(SELECTORS.SUMMARY).attr('content'),
   ),
 }