add baidu suggest

This commit is contained in:
hillerliao
2022-12-15 22:41:42 +08:00
parent 1d5c8dd1d7
commit 2013e37398
4 changed files with 48 additions and 1 deletions

View 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))
}

View File

@@ -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()