fix: 中国政府网吹风会和新闻页面格式调整 (#4406)
This commit is contained in:
parent
5c42be33b7
commit
8a5dbbcc1f
|
|
@ -55,37 +55,53 @@ module.exports = async (ctx) => {
|
|||
let fullTextGet = '';
|
||||
if (item.html().search(/dysMiddleResultConItemTitle/g) !== -1) {
|
||||
contentUrl = item.find('a').attr('href');
|
||||
description = await ctx.cache.tryGet(contentUrl, async () => {
|
||||
fullTextGet = await got.get(contentUrl);
|
||||
fullTextData = cheerio.load(fullTextGet.data);
|
||||
if (fullTextData.html().search(/pages_content/g) !== -1) {
|
||||
return fullTextData('.pages_content').html();
|
||||
} else {
|
||||
return fullTextData('#UCAP-CONTENT').html();
|
||||
}
|
||||
});
|
||||
if (contentUrl.search(/content/g) === -1) {
|
||||
description = item.find('a').text(); // 忽略获取吹风会的全文
|
||||
} else {
|
||||
description = await ctx.cache.tryGet(contentUrl, async () => {
|
||||
fullTextGet = await got.get(contentUrl);
|
||||
fullTextData = cheerio.load(fullTextGet.data);
|
||||
if (fullTextData.html().search(/pages_content/g) !== -1) {
|
||||
fullTextData('.shuzi').remove(); // 移除videobg的图片
|
||||
fullTextData('#myFlash').remove(); // 移除flash
|
||||
return fullTextData('.pages_content').html();
|
||||
} else {
|
||||
fullTextData('.shuzi').remove(); // 移除videobg的图片
|
||||
fullTextData('#myFlash').remove(); // 移除flash
|
||||
return fullTextData('#UCAP-CONTENT').html();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
href = item.find('a').attr('href');
|
||||
contentUrl = href.startsWith('/') ? `http://www.gov.cn${href}` : href;
|
||||
description = await ctx.cache.tryGet(contentUrl, async () => {
|
||||
fullTextGet = await got.get(contentUrl);
|
||||
fullTextData = cheerio.load(fullTextGet.data);
|
||||
const $1 = fullTextData.html();
|
||||
if (contentUrl.search(/zhengceku/g) !== -1) {
|
||||
fullText = fullTextData('.pages_content').html();
|
||||
} else {
|
||||
if ($1.search(/UCAP-CONTENT/g) === -1) {
|
||||
fullText = fullTextData('body').html();
|
||||
if (contentUrl.search(/content/g) === -1) {
|
||||
description = item.find('a').text(); // 忽略获取吹风会的全文
|
||||
} else {
|
||||
description = await ctx.cache.tryGet(contentUrl, async () => {
|
||||
fullTextGet = await got.get(contentUrl);
|
||||
fullTextData = cheerio.load(fullTextGet.data);
|
||||
const $1 = fullTextData.html();
|
||||
if (contentUrl.search(/zhengceku/g) !== -1) {
|
||||
// 政策文件库
|
||||
fullText = fullTextData('.pages_content').html();
|
||||
} else {
|
||||
fullTextData('.shuzi').remove();
|
||||
fullText = fullTextData('#UCAP-CONTENT').html();
|
||||
if ($1.search(/UCAP-CONTENT/g) === -1) {
|
||||
fullTextData('.shuzi').remove(); // 移除videobg的图片
|
||||
fullTextData('#myFlash').remove(); // 移除flash
|
||||
fullText = fullTextData('body').html();
|
||||
} else {
|
||||
fullTextData('.shuzi').remove(); // 移除videobg的图片
|
||||
fullTextData('#myFlash').remove(); // 移除flash
|
||||
fullText = fullTextData('#UCAP-CONTENT').html();
|
||||
}
|
||||
}
|
||||
}
|
||||
const regImg = /(img src=")(.*)(".*)/g;
|
||||
const regUrl = /(http.*\/)(content.*)/;
|
||||
const urlSplit = contentUrl.replace(regUrl, '$1');
|
||||
return fullText.replace(regImg, '$1' + urlSplit + '$2' + '$3');
|
||||
});
|
||||
const regImg = /(img src=")(.*)(".*)/g;
|
||||
const regUrl = /(http.*\/)(content.*)/;
|
||||
const urlSplit = contentUrl.replace(regUrl, '$1');
|
||||
return fullText.replace(regImg, '$1' + urlSplit + '$2' + '$3'); // 处理图片链接
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ module.exports = async (ctx) => {
|
|||
.map(async (index, item) => {
|
||||
item = $(item);
|
||||
const contenlUrl = item.find('a').attr('href');
|
||||
const description = await ctx.cache.tryGet(contenlUrl, async () => {
|
||||
const fullText = await got.get(contenlUrl);
|
||||
const fullTextData = cheerio.load(fullText.data);
|
||||
return fullTextData('.online_list').html();
|
||||
});
|
||||
// const description = await ctx.cache.tryGet(contenlUrl, async () => {
|
||||
// const fullText = await got.get(contenlUrl);
|
||||
// const fullTextData = cheerio.load(fullText.data);
|
||||
// return fullTextData('.online_list').html();
|
||||
// });
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
description: description,
|
||||
description: item.find('a').text(),
|
||||
link: contenlUrl,
|
||||
};
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue