소스 검색

Finish scraping data from JoB. TG-3 #ready-for-test

Tati 7 년 전
부모
커밋
4416267fe5
1개의 변경된 파일11개의 추가작업 그리고 1개의 파일을 삭제
  1. 11 1
      ktchn/src/recipes/scrape/sources/joy-of-baking.ts

+ 11 - 1
ktchn/src/recipes/scrape/sources/joy-of-baking.ts

@@ -10,6 +10,10 @@ const SELECTORS = {
   TITLE: 'h1 > span.Heading',
 }
 
+function cleanText(text: string): string {
+  return text.replace(/(\n|\t|\s{2,})/g, ' ').trim();
+}
+
 function getRecipeName($: CheerioSelector): string {
   return $(SELECTORS.TITLE).text().replace(/(.\n)?.Recipe.*/, '').trim();
 }
@@ -22,7 +26,7 @@ function getIngredients($: CheerioSelector): ComposedIngredients[] {
   let ingredients: ComposedIngredients[] = [];
   return rawData.reduce((list:any, element, index) => {
     let rawIngredient = $(element).text();
-    rawIngredient = rawIngredient.replace(/(\n|\t|\s{2,})/g, ' ').trim();
+    rawIngredient = cleanText(rawIngredient);
     let last = list.length - 1;
     if(isIngredient(element)) {
       let ingredient = parseIngredients(rawIngredient);
@@ -37,6 +41,11 @@ function getIngredients($: CheerioSelector): ComposedIngredients[] {
   }, ingredients);
 }
 
+function getInstructions($: CheerioSelector): string[] {
+  const rawData = $('td [style="border-top-style: none; border-top-width: medium"] p').toArray();
+  return rawData.map(element => cleanText($(element).text()));
+}
+
 
 const JOB_CONFIG = {
   name: 'Joy of Baking',
@@ -48,6 +57,7 @@ const JOB_CONFIG = {
       JOB_AUTHOR_DATA,
       new RecipeDetails(), // There is no way to scrape this data from JOB
       getIngredients($),
+      getInstructions($),
     ); 
   }
 }