diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 301b9f1..3e8a2d2 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -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//') +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/') def mp_gh(gh=''): from rsshub.spiders.mp.gh import ctx diff --git a/rsshub/spiders/producthunt/search.py b/rsshub/spiders/producthunt/search.py new file mode 100644 index 0000000..ea6f876 --- /dev/null +++ b/rsshub/spiders/producthunt/search.py @@ -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)) + } diff --git a/rsshub/spiders/zaobao/realtime.py b/rsshub/spiders/zaobao/realtime.py index 54f018e..4c32f78 100644 --- a/rsshub/spiders/zaobao/realtime.py +++ b/rsshub/spiders/zaobao/realtime.py @@ -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, diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index 1c9e5ab..11e8e73 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -368,6 +368,19 @@
+ +
+
+

Producthunt - 搜索结果

+
Producthunt - 搜索结果 by hillerliao
+

举例:https://pyrsshub.herokuapp.com/producthunt/search/wechat/30

+

路由:/producthunt/search/:keyword/:period

+

keyword [必填, 搜索关键词],period,[必填, 时间范围]

+
+
+
+ +