mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-05-14 07:26:44 +00:00
add producthunt search
This commit is contained in:
@@ -190,6 +190,12 @@ def mp_tag(mp='', tag=''):
|
||||
from rsshub.spiders.mp.tag import ctx
|
||||
return render_template('main/atom.xml', **filter_content(ctx(mp,tag)))
|
||||
|
||||
@bp.route('/producthunt/search/<string:keyword>/<string:period>')
|
||||
def producthunt_search(keyword='', period=''):
|
||||
from rsshub.spiders.producthunt.search import ctx
|
||||
return render_template('main/atom.xml', **filter_content(ctx(keyword,period)))
|
||||
|
||||
|
||||
@bp.route('/mp/gh/<string:gh>')
|
||||
def mp_gh(gh=''):
|
||||
from rsshub.spiders.mp.gh import ctx
|
||||
|
||||
30
rsshub/spiders/producthunt/search.py
Normal file
30
rsshub/spiders/producthunt/search.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import re
|
||||
import requests
|
||||
from rsshub.utils import fetch
|
||||
from rsshub.utils import DEFAULT_HEADERS
|
||||
|
||||
domain = 'https://www.producthunt.com'
|
||||
|
||||
|
||||
def parse(post):
|
||||
item = {}
|
||||
item['title'] = post.css('h3 a::text').extract_first()
|
||||
item['description'] = post.css('.styles_font__m46I_.styles_grey__YlBrh.styles_small__lLD08.styles_normal__FGFK7.styles_tagline__j29pO.styles_lineHeight__kGlRn::text').extract_first()
|
||||
item['link'] = domain + post.css('a::attr(href)').extract_first()
|
||||
return item
|
||||
|
||||
|
||||
def ctx(keyword='', period=''):
|
||||
DEFAULT_HEADERS.update({'Referer': domain})
|
||||
r_url = f'{domain}' + f'/search?q={keyword}&postedAfter={period}:days'
|
||||
print(r_url)
|
||||
tree = fetch(r_url,headers=DEFAULT_HEADERS)
|
||||
posts = tree.css('.styles_item__Sn_12')
|
||||
print(posts)
|
||||
return {
|
||||
'title': f'{keyword} - Producthunt',
|
||||
'link': r_url,
|
||||
'description': f'Producthunt - {r_url}',
|
||||
'author': 'hillerliao',
|
||||
'items': list(map(parse, posts))
|
||||
}
|
||||
@@ -15,7 +15,7 @@ def ctx(category=''):
|
||||
url = f"{domain}/realtime/{category}"
|
||||
tree = fetch(url,headers=DEFAULT_HEADERS)
|
||||
posts = tree.css('.col-lg-4.col-12.list-block.no-gutters')
|
||||
print(posts)
|
||||
# print(posts)
|
||||
return {
|
||||
'title': f'{category} - 早报网即时新闻',
|
||||
'link': url,
|
||||
|
||||
@@ -368,6 +368,19 @@
|
||||
<br>
|
||||
<!--item info end-->
|
||||
|
||||
<!--item info start-->
|
||||
<div class="card text-left">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">Producthunt - 搜索结果</h4>
|
||||
<h6 class="text-muted">Producthunt - 搜索结果 <a href="https://github.com/hillerliao" target="_blank" class="badge badge-secondary">by hillerliao</a></h6>
|
||||
<p class="card-text">举例:<a href="https://pyrsshub.herokuapp.com/producthunt/search/wechat/30" target="_blank">https://pyrsshub.herokuapp.com/producthunt/search/wechat/30</a></p>
|
||||
<p class="card-text">路由:<code>/producthunt/search/:keyword/:period</code></p>
|
||||
<p class="card-text">keyword [必填, 搜索关键词],period,[必填, 时间范围] </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