add producthunt search

This commit is contained in:
hillerliao
2022-03-31 10:46:19 +08:00
parent 6b034dd3e2
commit 486ca65885
4 changed files with 50 additions and 1 deletions

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

View File

@@ -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,