Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a9255ac

Browse files
title과 link를 크롤링하는 fetch.js 빌드
1 parent e216dae commit a9255ac

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎utils/fetch.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import fetch from 'node-fetch';
2+
import * as cheerio from 'cheerio';
3+
4+
async function fetchBody() {
5+
const COURSE_URL = 'https://programmers.co.kr/learn/courses/30';
6+
const response = await fetch(COURSE_URL);
7+
const body = await response.text();
8+
return body;
9+
}
10+
11+
export default async function fetchTitleLink() {
12+
const body = await fetchBody();
13+
const $ = cheerio.load(body);
14+
const lesson = {};
15+
16+
$('.lesson-title').each(function (index, el) {
17+
const title = $(el).children('span').text();
18+
const link = $(el).attr('href');
19+
lesson[title] = link;
20+
});
21+
return lesson;
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /