mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-05-14 15:09:23 +00:00
get infoq search result
This commit is contained in:
@@ -73,6 +73,11 @@ 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/<string:category>')
|
||||
def infoq_search(category=''):
|
||||
from rsshub.spiders.infoq.search import ctx
|
||||
return render_template('main/atom.xml', **filter_content(ctx(category)))
|
||||
|
||||
@bp.route('/dxzg/notice')
|
||||
def dxzg_notice():
|
||||
from rsshub.spiders.dxzg.notice import ctx
|
||||
|
||||
35
rsshub/spiders/infoq/search.py
Normal file
35
rsshub/spiders/infoq/search.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import requests
|
||||
import json
|
||||
from urllib.parse import unquote, quote
|
||||
from rsshub.utils import DEFAULT_HEADERS
|
||||
from rsshub.utils import fetch
|
||||
|
||||
domain = 'https://s.geekbang.org'
|
||||
|
||||
|
||||
def parse(post):
|
||||
item = {}
|
||||
item['title'] = post['title']
|
||||
item['description'] = post['simple_content']
|
||||
item['link'] = post['content_url']
|
||||
item['author'] = post['author']
|
||||
item['pubDate'] = post['release_time']
|
||||
return item
|
||||
|
||||
|
||||
def ctx(category=''):
|
||||
# category = unquote(category, encoding='utf-8')
|
||||
category1 = category.encode("utf-8").decode("latin-1")
|
||||
referer = f'{domain}/search/c=0/k={category1}/t=0'
|
||||
DEFAULT_HEADERS.update({'Referer': referer})
|
||||
url = f'{domain}/api/gksearch/search'
|
||||
payload = {"q":category,"t":0,"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,
|
||||
'description': f'{category} - 极客邦搜索 - InfoQ',
|
||||
'author': 'hillerliao',
|
||||
'items': list(map(parse, posts))
|
||||
}
|
||||
@@ -122,6 +122,10 @@
|
||||
<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/infoq/profile/8D1F7C1F2C23FD" target="_blank">https://pyrsshub.vercel.app/infoq/profile/8D1F7C1F2C23FD</a></p>
|
||||
<p class="card-text">路由:<code>/infoq/profile/:category</code></p>
|
||||
|
||||
<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/infoq/search/金融" target="_blank">https://pyrsshub.vercel.app/infoq/search/金融</a></p>
|
||||
<p class="card-text">路由:<code>/infoq/search/:category</code></p>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
Reference in New Issue
Block a user