From 8f1c7725246cce0930560f457aa0d5350f0addb9 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Sat, 22 Oct 2022 10:04:55 +0800 Subject: [PATCH] add type to infoq search query --- rsshub/blueprints/main.py | 6 +++--- rsshub/spiders/infoq/search.py | 8 ++++---- rsshub/templates/main/feeds.html | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 598a95b..0c48ddc 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -73,10 +73,10 @@ 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=''): +@bp.route('/infoq/search//') +def infoq_search(category='', type=''): from rsshub.spiders.infoq.search import ctx - return render_template('main/atom.xml', **filter_content(ctx(category))) + return render_template('main/atom.xml', **filter_content(ctx(category, type))) @bp.route('/dxzg/notice') def dxzg_notice(): diff --git a/rsshub/spiders/infoq/search.py b/rsshub/spiders/infoq/search.py index fb847ec..4e2c66f 100644 --- a/rsshub/spiders/infoq/search.py +++ b/rsshub/spiders/infoq/search.py @@ -17,18 +17,18 @@ def parse(post): return item -def ctx(category=''): +def ctx(category='', type=''): # category = unquote(category, encoding='utf-8') category1 = category.encode("utf-8").decode("latin-1") - referer = f'{domain}/search/c=0/k={category1}/t=0' + referer = f'{domain}/search/c=0/k={category1}/t={type}' DEFAULT_HEADERS.update({'Referer': referer}) url = f'{domain}/api/gksearch/search' - payload = {"q":category,"t":0,"s":20,"p":1} + payload = {"q":category,"t": type,"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, + 'link': f'{domain}/search/c=0/k={category}/t=0', 'description': f'{category} - 极客邦搜索 - InfoQ', 'author': 'hillerliao', 'items': list(map(parse, posts)) diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index 11c1d53..e870f04 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -124,8 +124,9 @@

路由:/infoq/profile/:category

搜索结果by hillerliao
-

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

-

路由:/infoq/search/:category

+

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

+

路由:/infoq/search/:category/:type

+

参数:category [必填,关键词],type [必填,类型,0 全部 | 1 微信公众号 | 2 infoQ网站 ]