fix ph search fetching

This commit is contained in:
hillerliao
2022-05-16 23:51:00 +08:00
parent c3ad977dc7
commit 1d31f87f7b

View File

@@ -8,8 +8,8 @@ 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['title'] = post.css('a.styles_title__hxNoA::text').extract_first()
item['description'] = post.css('a.styles_tagline__qrpWc::text').extract_first()
item['link'] = domain + post.css('a::attr(href)').extract_first()
return item
@@ -17,10 +17,10 @@ def parse(post):
def ctx(keyword='', period=''):
DEFAULT_HEADERS.update({'Referer': domain})
r_url = f'{domain}' + f'/search?q={keyword}&postedAfter={period}:days'
print(r_url)
# print(r_url)
tree = fetch(r_url,headers=DEFAULT_HEADERS)
posts = tree.css('.styles_item__Sn_12')
print(posts)
posts = tree.css('.style_layoutMain___pXHk').css('.style_px-mobile-1__DSM5j.style_px-tablet-1__R5dkv.style_pt-mobile-0__lBXpV.style_pt-desktop-6__eNi8V.style_pt-tablet-6__BJU9d.style_pt-widescreen-6__SWPD_.style_pb-mobile-7__OX0Sz.style_pb-desktop-6__EZ3zm.style_pb-tablet-6__F61Qx.style_pb-widescreen-6__UB2pW')
# print(posts)
return {
'title': f'{keyword} - Producthunt',
'link': r_url,