From 5cb773b6a9fa6255a4c421f5d60ad736fc1900b0 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Thu, 23 Apr 2020 21:54:04 +0800 Subject: [PATCH] add benzinga ratings --- rsshub/blueprints/main.py | 7 ++++++- rsshub/spiders/benzinga/ratings.py | 27 +++++++++++++++++++++++++++ rsshub/templates/main/feeds.html | 13 +++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 rsshub/spiders/benzinga/ratings.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index cb9b34d..2553a5e 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -150,4 +150,9 @@ def jintiankansha_column(category=''): @bp.route('/interotc/cpgg/') def interotc_cpgg(category=''): from rsshub.spiders.interotc.cpgg import ctx - return render_template('main/atom.xml', **filter_content(ctx(category))) \ No newline at end of file + return render_template('main/atom.xml', **filter_content(ctx(category))) + +@bp.route('/benzinga/ratings/') +def benzinga_ratings(category=''): + from rsshub.spiders.benzinga.ratings import ctx + return render_template('main/atom.xml', **filter_content(ctx(category))) \ No newline at end of file diff --git a/rsshub/spiders/benzinga/ratings.py b/rsshub/spiders/benzinga/ratings.py new file mode 100644 index 0000000..8474efb --- /dev/null +++ b/rsshub/spiders/benzinga/ratings.py @@ -0,0 +1,27 @@ +from rsshub.utils import DEFAULT_HEADERS +from rsshub.utils import fetch + +domain = 'https://www.benzinga.com/' + +def ctx(category=''): + + stock = category + + def parse(post): + item = {} + item['description'] = item['title'] = stock.upper() + '的评级:' + ', '.join(post.css('td::text').extract()) + return item + + url = f'{domain}/stock/{category}/ratings' + tree = fetch(url, headers=DEFAULT_HEADERS) + posts = tree.css('tr') + items = list(map(parse, posts)) + + column_title = tree.css('title::text').extract_first() + return { + 'title': f'{column_title} - benzinga', + 'description': f'{column_title} - benzinga', + 'link': url, + 'author': f'hillerliao', + 'items': items + } diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index ff1fb61..9b6a0f8 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -270,4 +270,17 @@
+ +
+
+

股票评级 - Benzinga

+
股票评级 - Benzinga by hillerliao
+

举例:https://pyrsshub.herokuapp.com/benzinga/ratings/wb

+

路由:/benzinga/ratings/:category

+

参数:category [必填, 股票代码]

+
+
+
+ + {% endblock content %} \ No newline at end of file