Selaa lähdekoodia

Add Maangchi's website to scrape sources

Tatiana Inama 6 vuotta sitten
vanhempi
commit
97855570cd

+ 2 - 0
ktchn/src/recipes/scrape/sources/index.ts

@@ -3,6 +3,7 @@ import JOB from './joy-of-baking';
 import AR from './all-recipes';
 import HCA from './home-cooking-adventure';
 import JOC from './just-one-cookbook';
+import MAANGCHI from './maangchi';
 import { Recipe } from '../../model';
 
 
@@ -19,6 +20,7 @@ const Sources: ScrapingSource[] = [
   AR,
   HCA,
   JOC,
+  MAANGCHI
 ];
 
 export default Sources;

+ 40 - 0
ktchn/src/recipes/scrape/sources/maangchi.ts

@@ -0,0 +1,40 @@
+import { Recipe, ISubRecipe } from "../../model";
+import { parseIngredients } from '../index';
+import { getText, getTextList } from './../service';
+
+function getIngredients($: CheerioSelector): ISubRecipe[] {
+  return $('.entry.clearfix ul').map((i, subRecipe) => {
+    return {
+      name: '',
+      ingredients: $(subRecipe).find('li').map((i, ing) => parseIngredients($(ing).text().trim())).get()
+    }
+  }).get();
+}
+
+function getInstructions($: CheerioSelector): string [] {
+  return $('.entry.clearfix ol li').map((i, instruction) => $(instruction).text().trim()).get()
+}
+
+const MAANGCHI_CONFIG = {
+  name: 'Maangchi',
+  domain: 'maangchi',
+  website: 'https://www.maangchi.com',
+  scrapeRecipe: ($: CheerioSelector): Recipe => ({
+    name: getText($)('h1.entry-title'),
+    author: { 
+      name: 'Maangchi', website: 'https://www.maangchi.com' },
+    details: {
+      cookingTime: '',
+      servings: 1,
+      preparationTime: '',
+      video: $('iframe').attr('src'),
+    },
+    ingredients: getIngredients($),
+    instructions: getInstructions($),
+    summary: $('.entry.clearfix > p').text().trim(),
+    tags: getTextList($)('.sidebar li span[itemprop="recipeCategory"] a'),
+    image: $('img.video-embed-poster').attr('src')
+  }),
+}
+
+export default MAANGCHI_CONFIG;