mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-05-20 07:26:47 +00:00
add baidu suggest
This commit is contained in:
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()
|
||||
|
||||
Reference in New Issue
Block a user