-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipe_list.js
45 lines (37 loc) · 1.2 KB
/
recipe_list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const axios = require("axios");
const cheerio = require("cheerio");
const express = require('express');
const app = express();
const cors = require('cors');
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const crop = "옥수수";
const getHtml = async () => {
try {
return await axios.get("https://www.2bob.co.kr/search_list.php?a=result_recipe&fKeyValue=" + crop);
} catch (error) {
console.error(error);
}
};
getHtml()
.then(html => {
const $ = cheerio.load(html.data);
const RecipeList = $("div.contain > div.search_con > div > ul > li");
const recipeListData = RecipeList
.map((index, div) => ({
id: index,
link: 'https://www.2bob.co.kr'+ $(div).find("a").attr('href'),
img_url: 'https://www.2bob.co.kr/'+ $(div).find("a > div.img_wrap > img").attr('src'),
sub_title: $(div).find("a > div.text_box > p.s_title").text(),
title: $(div).find("a > div.text_box > p.b_title").text(),
}))
.toArray();
console.log(recipeListData);
app.get('/api/recipe', (req, res) => {
res.json(recipeListData);
});
});
app.listen(3000, () => {
console.log('server start!!');
});