mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-05-14 15:09:23 +00:00
add baidu suggest
This commit is contained in:
@@ -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/<string:category>')
|
||||
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/<string:gh>')
|
||||
def mp_gh(gh=''):
|
||||
from rsshub.spiders.mp.gh import ctx
|
||||
|
||||
29
rsshub/spiders/baidu/suggest.py
Normal file
29
rsshub/spiders/baidu/suggest.py
Normal file
@@ -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))
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -42,6 +42,19 @@
|
||||
<br>
|
||||
<!--item info end-->
|
||||
|
||||
<!--item info start-->
|
||||
<div class="card text-left">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">搜索提示 - 百度</h4>
|
||||
<h6 class="text-muted">搜索提示 - 百度<a href="https://github.com/hillerliao" target="_blank" class="badge badge-secondary">by hillerliao</a></h6>
|
||||
<p class="card-text">举例:<a href="https://pyrsshub.vercel.app/baidu/suggest/weishenme" target="_blank">https://pyrsshub.vercel.app/baidu/suggest/weishenme</a></p>
|
||||
<p class="card-text">路由:<code>/baidu/suggest/:category</code></p>
|
||||
<p class="card-text">参数:category,关键词</p>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<!--item info end-->
|
||||
|
||||
<!--item info start-->
|
||||
<div class="card text-left">
|
||||
<div class="card-body">
|
||||
|
||||
Reference in New Issue
Block a user