Files
RSSHub-python/rsshub/spiders/pgyer/app.py
2022-04-29 18:54:56 +08:00

31 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import re
from rsshub.utils import DEFAULT_HEADERS
from rsshub.utils import fetch
domain = 'https://www.pgyer.com'
def ctx(category=''):
url = f"{domain}/{category}"
tree = fetch(url,headers=DEFAULT_HEADERS)
posts = tree.css('.container.content.pt-10')
posts = tree.css('html')
title = tree.xpath('//meta[@property="og:description"]').attrib['content']
app_name = tree.css('title::text').get()
return {
'title': f'{title} - 蒲公英',
'link': url,
'description': f'{app_name} 安装包更新 - 蒲公英',
'author': 'hillerliao',
'items': list(map(parse, posts))
}
def parse(post):
item = {}
item['title'] = post.xpath('//meta[@property="og:description"]').attrib['content']
item['description'] = item['title'] + '' \
+ post.css('ul.breadcrumb > li::text').getall()[1] + '' \
+ post.css('ul.breadcrumb > li::text').getall()[2]
item['description'] = re.sub(r'\s|\n', '', item['description'])
link = post.css('img.qrcode').attrib['src'].split('app/qrcode/')
item['link'] = link[0] + link[1]
return item