fix: tprtc news 404 (#2627)

This commit is contained in:
Cloud 2019-07-16 21:45:24 +08:00 committed by DIYgod
parent 219ea0dcd3
commit 1370d71b3d
4 changed files with 45 additions and 34 deletions

View File

@ -198,14 +198,14 @@ pageClass: routes
<Route author="SunShinenny" example="/gov/veterans/index" path="/gov/veterans/index"/>
## 中央纪委国家监委
### 审查调查
<Route author="LogicJake" example="/ccdi/scdc" path="/ccdi/scdc"/>
## 中华人民共和国外交部
### 发言人表态
<Route author="nicolaszf" example="/gov/fmprc/fyrbt" path="/gov/fmprc/fyrbt"/>
## 中央纪委国家监委
### 审查调查
<Route author="LogicJake" example="/ccdi/scdc" path="/ccdi/scdc"/>

View File

@ -3,12 +3,14 @@ const cheerio = require('cheerio');
const url = require('url');
module.exports = async (ctx) => {
const pagelink = 'http://otc.tprtc.com/tjcqp/cgq/search/index';
const host = 'http://otc.tprtc.com';
const response = await got({
method: 'get',
url: 'http://item.tprtc.com/tjcqp/cgq/search/search_li?xxplfs=&zrdj=0&nzrbl=0&hy=&szdq=&sortTag=0&pageNo=1&pageSize=20&keyWord=',
url: 'http://otc.tprtc.com/tjcqp/cgq/search/search_li',
headers: {
Referer: 'http://item.tprtc.com/tjcqp/cgq/search/index?plfs=2',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3793.0 Safari/537.36',
Referer: pagelink,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
},
@ -24,8 +26,7 @@ module.exports = async (ctx) => {
method: 'get',
url: link,
headers: {
Referer: 'http://item.tprtc.com/tjcqp/cgq/search/index?plfs=2',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3793.0 Safari/537.36',
Referer: pagelink,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
},
@ -36,8 +37,8 @@ module.exports = async (ctx) => {
$('.bd_detail_main .bd_detail_tab').remove();
// 文章样式
const style = `<link rel="stylesheet" href="http://item.tprtc.com/res/prj/tjcq/css/notheme/notheme_all_min.css" type="text/css">
<link rel="stylesheet" href="http://item.tprtc.com/res/prj/tjcq/css/themes/default/common_all_min.css" type="text/css"/>`;
const style = `<link rel="stylesheet" href="http://otc.tprtc.com/res/prj/tjcq/css/notheme/notheme_all_min.css" type="text/css">
<link rel="stylesheet" href="http://otc.tprtc.com/res/prj/tjcq/css/themes/default/common_all_min.css" type="text/css"/>`;
// 提取内容
const description = $('.bd_detail_main').html() + style;
@ -45,7 +46,6 @@ module.exports = async (ctx) => {
return description;
};
const host = 'http://item.tprtc.com';
const items = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
@ -73,7 +73,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: '产权转让-天津产权交易中心',
link: 'http://item.tprtc.com/tjcqp/cgq/search/index?plfs=2',
link: pagelink,
description: '天津产权交易中心-产权转让',
item: items,
};

View File

@ -1,13 +1,16 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
module.exports = async (ctx) => {
const pagelink = 'http://www.tprtc.com/page/channel/news?id=89';
const host = 'http://www.tprtc.com';
const response = await got({
method: 'get',
url: 'http://www.tprtc.com/InformationChannel/index.jhtml',
url: pagelink,
headers: {
Referer: 'http://www.tprtc.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3793.0 Safari/537.36',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
},
@ -16,21 +19,29 @@ module.exports = async (ctx) => {
const data = response.data;
const $ = cheerio.load(data);
const list = $('.c1-bline').get();
const list = $('.news_list li').get();
const ProcessFeed = async (link) => {
const response = await got.get(link);
const response = await got({
method: 'get',
url: link,
headers: {
Referer: pagelink,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
},
});
const $ = cheerio.load(response.data);
return $('.content').html();
return $('.new_detail_cont').html();
};
const items = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const $title = $('.f-left>a:last-child');
const itemUrl = $title.attr('href');
const $title = $('a');
const itemUrl = url.resolve(host, $title.attr('href'));
const cache = await ctx.cache.get(itemUrl);
if (cache) {
@ -40,10 +51,10 @@ module.exports = async (ctx) => {
const description = await ProcessFeed(itemUrl);
const single = {
title: $('a.red').text() + ' ' + $title.attr('title'),
title: $title.attr('title'),
link: itemUrl,
description,
author: $('a.red').text(),
pubDate: new Date($('.news_time').text()).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
@ -53,7 +64,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: '新闻动态-天津产权交易中心',
link: 'http://www.tprtc.com/InformationChannel/index.jhtml',
link: pagelink,
description: '天津产权交易中心-新闻动态',
item: items,
};

View File

@ -3,12 +3,14 @@ const cheerio = require('cheerio');
const url = require('url');
module.exports = async (ctx) => {
const pagelink = 'http://otc.tprtc.com/tjcqp/s/jyzx/qyzc';
const host = 'http://otc.tprtc.com';
const response = await got({
method: 'get',
url: 'http://item.tprtc.com/tjcqp/s/jyzx/qyzc_li?plfs=&gpjg=&szdq=&sortTag=0&pageSize=20&pageNo=1&keyWord=',
url: 'http://otc.tprtc.com/tjcqp/s/jyzx/qyzc_li',
headers: {
Referer: 'http://item.tprtc.com/tjcqp/s/jyzx/qyzc',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3793.0 Safari/537.36',
Referer: pagelink,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
},
@ -24,8 +26,7 @@ module.exports = async (ctx) => {
method: 'get',
url: link,
headers: {
Referer: 'http://item.tprtc.com/tjcqp/s/jyzx/qyzc',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3793.0 Safari/537.36',
Referer: pagelink,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
},
@ -39,8 +40,8 @@ module.exports = async (ctx) => {
$('.bd_detail_left [id^="clob_formweb_value_"]').remove();
// 文章样式
const style = `<link rel="stylesheet" href="http://item.tprtc.com/res/prj/tjcq/css/notheme/notheme_all_min.css" type="text/css">
<link rel="stylesheet" href="http://item.tprtc.com/res/prj/tjcq/css/themes/default/common_all_min.css" type="text/css"/>`;
const style = `<link rel="stylesheet" href="http://otc.tprtc.com/res/prj/tjcq/css/notheme/notheme_all_min.css" type="text/css">
<link rel="stylesheet" href="http://otc.tprtc.com/res/prj/tjcq/css/themes/default/common_all_min.css" type="text/css"/>`;
// 提取内容
const description = $('.bd_detail_left').html() + style;
@ -48,7 +49,6 @@ module.exports = async (ctx) => {
return description;
};
const host = 'http://item.tprtc.com';
const items = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
@ -77,7 +77,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: '企业资产转让-天津产权交易中心',
link: 'http://item.tprtc.com/tjcqp/s/jyzx/qyzc',
link: pagelink,
description: '天津产权交易中心-企业资产转让',
item: items,
};