diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 2ead56d..df1e3b0 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -240,6 +240,31 @@ def mp_youwuqiong(author=''): from rsshub.spiders.mp.youwuqiong import ctx return render_template('main/atom.xml', **filter_content(ctx(author))) + +@bp.route('/xinhuanet/zuixinbobao') +def xinhuanet_zuixinbobao(): + from rsshub.spiders.xinhuanet.zuixinbobao import ctx + return render_template('main/atom.xml', **filter_content(ctx())) + + +@bp.route('/xinhuanet/shizhenglianbo') +def xinhuanet_shizhenglianbo(): + from rsshub.spiders.xinhuanet.shizhenglianbo import ctx + return render_template('main/atom.xml', **filter_content(ctx())) + + +@bp.route('/xinhuanet/yaodianjujiao') +def xinhuanet_yaodianjujiao(): + from rsshub.spiders.xinhuanet.yaodianjujiao import ctx + return render_template('main/atom.xml', **filter_content(ctx())) + + +@bp.route('/xinhuanet/world') +def xinhuanet_world(): + from rsshub.spiders.xinhuanet.world import ctx + return render_template('main/atom.xml', **filter_content(ctx())) + + @bp.route('/yfchuhai/express/') def yfchuhai_express(): from rsshub.spiders.yfchuhai.express import ctx diff --git a/rsshub/spiders/xinhuanet/shizhenglianbo.py b/rsshub/spiders/xinhuanet/shizhenglianbo.py new file mode 100644 index 0000000..0c9bef9 --- /dev/null +++ b/rsshub/spiders/xinhuanet/shizhenglianbo.py @@ -0,0 +1,32 @@ +import json + +import requests + +from rsshub.utils import DEFAULT_HEADERS + +domain = 'http://www.news.cn' + + +def parse(post): + item = {} + item['title'] = post['Title'] + item['description'] = post['Abstract'] + item['link'] = post['LinkUrl'] + return item + + +def ctx(): + url = 'http://da.wa.news.cn/nodeart/page' + posts = requests.get( + url, + params={'nid': '113351', 'pgnum': '1', 'cnt': '20'}, + headers=DEFAULT_HEADERS, + ).text + posts = json.loads(posts)['data']['list'] + return { + 'title': '新华网 - 时政联播', + 'link': url, + 'description': '新华网 - 时政联播', + 'author': 'flyingicedragon', + 'items': list(map(parse, posts)), + } diff --git a/rsshub/spiders/xinhuanet/utils.py b/rsshub/spiders/xinhuanet/utils.py new file mode 100644 index 0000000..e5f83a6 --- /dev/null +++ b/rsshub/spiders/xinhuanet/utils.py @@ -0,0 +1,14 @@ +from rsshub.utils import DEFAULT_HEADERS, fetch + + +def parse_html(post): + item = {} + item['title'] = post.xpath('text()').extract_first() + item['link'] = post.xpath('@href').extract_first() + print(item['link']) + item['description'] = ( + fetch(item['link'], headers=DEFAULT_HEADERS) + .xpath('//div[@id=\'detail\']') + .get() + ) + return item diff --git a/rsshub/spiders/xinhuanet/world.py b/rsshub/spiders/xinhuanet/world.py new file mode 100644 index 0000000..4b89e05 --- /dev/null +++ b/rsshub/spiders/xinhuanet/world.py @@ -0,0 +1,19 @@ +from rsshub.spiders.xinhuanet.utils import parse_html as parse +from rsshub.utils import DEFAULT_HEADERS, fetch + +domain = 'http://www.news.cn/world/index.html' + + +def ctx(): + url = f'{domain}' + tree = fetch(url, headers=DEFAULT_HEADERS) + with open('/home/icedragon/tmp.html', 'w') as log: + log.write(tree.getall()[0]) + posts = tree.xpath('//div[@id=\'recommendDepth\']//a') + return { + 'title': '新华网 - 国际要闻', + 'link': url, + 'description': '新华网 - 国际要闻', + 'author': 'flyingicedragon', + 'items': list(map(parse, posts)), + } diff --git a/rsshub/spiders/xinhuanet/yaodianjujiao.py b/rsshub/spiders/xinhuanet/yaodianjujiao.py new file mode 100644 index 0000000..79258cd --- /dev/null +++ b/rsshub/spiders/xinhuanet/yaodianjujiao.py @@ -0,0 +1,17 @@ +from rsshub.spiders.xinhuanet.utils import parse_html as parse +from rsshub.utils import DEFAULT_HEADERS, fetch + +domain = 'http://www.news.cn' + + +def ctx(): + url = f'{domain}' + tree = fetch(url, headers=DEFAULT_HEADERS) + posts = tree.xpath('//div[@id=\'depth\']//li/a') + return { + 'title': '新华网 - 要点聚焦', + 'link': url, + 'description': '新华网 - 要点聚焦', + 'author': 'flyingicedragon', + 'items': list(map(parse, posts)), + } diff --git a/rsshub/spiders/xinhuanet/zuixinbobao.py b/rsshub/spiders/xinhuanet/zuixinbobao.py new file mode 100644 index 0000000..f1534fe --- /dev/null +++ b/rsshub/spiders/xinhuanet/zuixinbobao.py @@ -0,0 +1,17 @@ +from rsshub.spiders.xinhuanet.utils import parse_html as parse +from rsshub.utils import DEFAULT_HEADERS, fetch + +domain = 'http://www.news.cn' + + +def ctx(): + url = f'{domain}' + tree = fetch(url, headers=DEFAULT_HEADERS) + posts = tree.xpath('//div[@id=\'latest\']//li/a') + return { + 'title': '新华网 - 最新播报', + 'link': url, + 'description': '新华网 - 最新播报', + 'author': 'flyingicedragon', + 'items': list(map(parse, posts)), + } diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index 1302710..b91145f 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -538,6 +538,27 @@
+ +
+
+

新华网

+
新华网 - 最新播报by flyingicedragon
+

举例:https://pyrsshub.vercel.app/xinhuanet/zuixinbobao

+

路由:/xinhuanet/zuixinbobao

+
新华网 - 时政联播by flyingicedragon
+

举例:https://pyrsshub.vercel.app/xinhuanet/shizhenglianbo

+

路由:/xinhuanet/shizhenglianbo

+
新华网 - 要点聚焦by flyingicedragon
+

举例:https://pyrsshub.vercel.app/xinhuanet/yaodianjujiao

+

路由:/xinhuanet/yaodianjujiao

+
新华网 - 时政联播by flyingicedragon
+

举例:https://pyrsshub.vercel.app/xinhuanet/world

+

路由:/xinhuanet/world

+
+
+
+ +