-
https://info.51.ca/news/digest/ const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: 'https://info.51.ca/news/digest/',
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('div.textbox > h3 > a');
let itemPicUrl;
ctx.state.data = {
title: '51.新闻精要',
link: 'https://info.51.ca/news/digest/',
item:
list &&
list
.map((index, item) => {
item = $(item);
itemPicUrl = '';
return {
title: item.text(),
description: `description`,
link: item.attr('href'),
};
})
.get(),
};
};
|
Beta Was this translation helpful? Give feedback.
Answered by
shawn8888
Jan 10, 2022
Replies: 1 comment 1 reply
-
自己找到答案了: |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
shawn8888
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
自己找到答案了:
got加一个参数:responseType: 'buffer',
然后:const $ = cheerio.load((iconv.decode(response.data, 'GBK')));