From 2013e37398e2c7ae3b2854a31df18e9aa15b1c05 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Thu, 15 Dec 2022 22:41:42 +0800 Subject: [PATCH] add baidu suggest --- rsshub/blueprints/main.py | 5 +++++ rsshub/spiders/baidu/suggest.py | 29 ++++++++++++++++++++++++++++ rsshub/spiders/producthunt/search.py | 2 +- rsshub/templates/main/feeds.html | 13 +++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 rsshub/spiders/baidu/suggest.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 8629d51..dd856da 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -219,6 +219,11 @@ def economist_wordlbrief(category=''): from rsshub.spiders.economist.worldbrief import ctx return render_template('main/atom.xml', **filter_content(ctx(category))) +@bp.route('/baidu/suggest/') +def baidu_suggest(category=''): + from rsshub.spiders.baidu.suggest import ctx + return render_template('main/atom.xml', **filter_content(ctx(category))) + @bp.route('/mp/gh/') def mp_gh(gh=''): from rsshub.spiders.mp.gh import ctx diff --git a/rsshub/spiders/baidu/suggest.py b/rsshub/spiders/baidu/suggest.py new file mode 100644 index 0000000..a5b3ba4 --- /dev/null +++ b/rsshub/spiders/baidu/suggest.py @@ -0,0 +1,29 @@ +import json +import requests +import arrow +from rsshub.utils import DEFAULT_HEADERS + +domain = 'https://baidu.com' + + +def parse(post): + item = {} + item['title'] = post['q'] + item['description'] = post['q'] + item['link'] = f'{domain}/s?ie=UTF-8&wd=' + post['q'] + item['pubDate'] = arrow.now().isoformat() + item['author'] = '百度' + return item + + +def ctx(category=''): + url = f'{domain}/sugrec?wd={category}&pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=37858,36557,37691,37908,37919,37758,37903,26350,37957,37881&req=2&csor=3&pwd=ruhe%20&cb=jQuery110209380107568499061_1671113820948&_=1671113820958' + posts = requests.get(url).text.split('(')[-1].split(')')[0] + posts = json.loads(posts)['g'] + return { + 'title': f'{category} - 搜索提示 - 百度', + 'link': f'https://www.baidu.com/s?ie=UTF-8&wd={category}', + 'description': f'百度搜索提示', + 'author': 'hillerliao', + 'items': list(map(parse, posts)) + } \ No newline at end of file diff --git a/rsshub/spiders/producthunt/search.py b/rsshub/spiders/producthunt/search.py index e1aab14..7fb10ef 100644 --- a/rsshub/spiders/producthunt/search.py +++ b/rsshub/spiders/producthunt/search.py @@ -17,7 +17,7 @@ def parse(post): return item -def ctx(keyword='', period=''): +def ctx2(keyword='', period=''): DEFAULT_HEADERS.update({'Referer': domain}) r_url = f'{domain}' + f'/search?q={keyword}&postedAfter={period}:days' browser = uc.Chrome() diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index b4915b5..a2c8ac5 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -42,6 +42,19 @@
+ +
+
+

搜索提示 - 百度

+
搜索提示 - 百度by hillerliao
+

举例:https://pyrsshub.vercel.app/baidu/suggest/weishenme

+

路由:/baidu/suggest/:category

+

参数:category,关键词

+
+
+
+ +