fetch article for mp tag page

This commit is contained in:
hillerliao
2021-08-07 21:38:45 +08:00
parent 41d2e57a19
commit 01fbea43c6
3 changed files with 44 additions and 0 deletions

View File

@@ -169,3 +169,7 @@ def chouti_section(category=''):
def chouti_search(category=''):
from rsshub.spiders.chouti.search import ctx
return render_template('main/atom.xml', **filter_content(ctx(category)))
@bp.route('/mp/tag/<string:mp>/<string:tag>')
def mp_tag(mp='', tag=''):
from rsshub.spiders.mp.tag import ctx
return render_template('main/atom.xml', **filter_content(ctx(mp,tag)))

27
rsshub/spiders/mp/tag.py Normal file
View File

@@ -0,0 +1,27 @@
from rsshub.utils import fetch
domain = 'https://mp.weixin.qq.com'
def parse(post):
item = {}
item['description'] = item['title'] = post.css('span.album__item-title-wrp::text').extract_first()
link = f"{post.css('li::attr(data-link)').extract_first()}"
item['link'] = link
item['pubDate'] = post.css('span.js_article_create_time::text').extract_first()
return item
def ctx(biz='', tag=''):
url = f"{domain}/mp/appmsgalbum?__biz={biz}==&action=getalbum&album_id={tag}"
tree = fetch(url)
posts = tree.css('.js_album_list li')
mp_name = tree.css('div.album__author-name::text').extract_first()
tag_name = tree.css('div#js_tag_name::text').extract_first()
return {
'title': f'{tag_name} - {mp_name}',
'link': url,
'description': f'{tag_name} - {mp_name}',
'author': 'hillerliao',
'items': list(map(parse, posts))
}

View File

@@ -309,4 +309,17 @@
<br>
<!--item info end-->
<!--item info start-->
<div class="card text-left">
<div class="card-body">
<h4 class="card-title">微信公众号 - 标签文章列表</h4>
<h6 class="text-muted">微信公众号 - 标签文章列表 <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/mp/tag/MzI5MjM3OTA0MA/1500461858015772673" target="_blank">https://pyrsshub.herokuapp.com/mp/tag/MzI5MjM3OTA0MA/1500461858015772673</a></p>
<p class="card-text">路由:<code>/mp/tag/:biz/:tag</code></p>
<p class="card-text">biz [必填, 公众号id]tag[必填, 标签 id] </p>
</div>
</div>
<br>
<!--item info end-->
{% endblock content %}