From a38d458e7d0e38c7d7edeb6127529f0df17415d7 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Sat, 22 Oct 2022 09:50:16 +0800 Subject: [PATCH] get infoq search result --- rsshub/blueprints/main.py | 5 +++++ rsshub/spiders/infoq/search.py | 35 ++++++++++++++++++++++++++++++++ rsshub/templates/main/feeds.html | 4 ++++ 3 files changed, 44 insertions(+) create mode 100644 rsshub/spiders/infoq/search.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 48cc50f..598a95b 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -73,6 +73,11 @@ def infoq_profile(category=''): from rsshub.spiders.infoq.profile import ctx return render_template('main/atom.xml', **filter_content(ctx(category))) +@bp.route('/infoq/search/') +def infoq_search(category=''): + from rsshub.spiders.infoq.search import ctx + return render_template('main/atom.xml', **filter_content(ctx(category))) + @bp.route('/dxzg/notice') def dxzg_notice(): from rsshub.spiders.dxzg.notice import ctx diff --git a/rsshub/spiders/infoq/search.py b/rsshub/spiders/infoq/search.py new file mode 100644 index 0000000..fb847ec --- /dev/null +++ b/rsshub/spiders/infoq/search.py @@ -0,0 +1,35 @@ +import requests +import json +from urllib.parse import unquote, quote +from rsshub.utils import DEFAULT_HEADERS +from rsshub.utils import fetch + +domain = 'https://s.geekbang.org' + + +def parse(post): + item = {} + item['title'] = post['title'] + item['description'] = post['simple_content'] + item['link'] = post['content_url'] + item['author'] = post['author'] + item['pubDate'] = post['release_time'] + return item + + +def ctx(category=''): + # category = unquote(category, encoding='utf-8') + category1 = category.encode("utf-8").decode("latin-1") + referer = f'{domain}/search/c=0/k={category1}/t=0' + DEFAULT_HEADERS.update({'Referer': referer}) + url = f'{domain}/api/gksearch/search' + payload = {"q":category,"t":0,"s":20,"p":1} + posts = requests.post(url, json=payload, headers=DEFAULT_HEADERS) + posts = json.loads(posts.text)['data']['list'] + return { + 'title': f'{category} - 搜索 - InfoQ', + 'link': referer, + 'description': f'{category} - 极客邦搜索 - InfoQ', + 'author': 'hillerliao', + 'items': list(map(parse, posts)) + } \ No newline at end of file diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index b2774b4..11c1d53 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -122,6 +122,10 @@
作者内容by hillerliao

举例:https://pyrsshub.vercel.app/infoq/profile/8D1F7C1F2C23FD

路由:/infoq/profile/:category

+ +
搜索结果by hillerliao
+

举例:https://pyrsshub.vercel.app/infoq/search/金融

+

路由:/infoq/search/:category