Showing
1 changed file
with
34 additions
and
0 deletions
testcode/test2.js
0 → 100644
1 | +const axios = require("axios"); | ||
2 | +const cheerio = require("cheerio"); | ||
3 | + | ||
4 | +const url = "https://news.zum.com/issuelist/58654445" | ||
5 | + | ||
6 | +const getHtml = async () => { | ||
7 | + try { | ||
8 | + return await axios.get(url); | ||
9 | + } catch (error) { | ||
10 | + console.error(error); | ||
11 | + } | ||
12 | +}; | ||
13 | + | ||
14 | +getHtml() | ||
15 | + .then(html => { | ||
16 | + let ulList = []; | ||
17 | + const $ = cheerio.load(html.data); | ||
18 | + const $bodyList = $("div.major_news > ul").children("ul.no_reply > li.large"); | ||
19 | + | ||
20 | + $bodyList.each(function(i, elem) { | ||
21 | + ulList[i] = { | ||
22 | + url: 'news.zum.com' + $(this).find('div.img > a').attr('href'), | ||
23 | + image_url: $(this).find('div.img > a > img').attr('src'), | ||
24 | + title: $(this).find('div.txt > div.title > a').text(), | ||
25 | + summary: $(this).find('div.txt > div.content > a').text(),//.slice(0, -29) | ||
26 | + datetime: $(this).find('div.txt > div.content > span.etc').text() | ||
27 | + }; | ||
28 | + //console.log(ulList[i]) // list object checking code | ||
29 | + }); | ||
30 | + | ||
31 | + const data = ulList.filter(n => n.title); | ||
32 | + return data; | ||
33 | + //return ulList; | ||
34 | + }).then(res => console.log(res)); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment