diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 0c0e338..3c152bc 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -121,6 +121,11 @@ def techcrunch_tag(category=''): from rsshub.spiders.techcrunch.tag import ctx return render_template('main/atom.xml', **filter_content(ctx(category))) +@bp.route('/weiyangx/home') +def weiyangx_home(): + from rsshub.spiders.weiyangx.home import ctx + return render_template('main/atom.xml', **filter_content(ctx())) + @bp.route('/weiyangx/express/') def weiyangx_express(): from rsshub.spiders.weiyangx.express import ctx diff --git a/rsshub/spiders/weiyangx/express.py b/rsshub/spiders/weiyangx/express.py index 929655a..da9652f 100644 --- a/rsshub/spiders/weiyangx/express.py +++ b/rsshub/spiders/weiyangx/express.py @@ -1,5 +1,6 @@ import requests import json +from parsel import Selector from rsshub.utils import DEFAULT_HEADERS domain = 'https://www.weiyangx.com' @@ -18,14 +19,11 @@ def parse(post): def ctx(): - url = f'https://www.weiyangx.com/wp-admin/admin-ajax.php' - q_data = {"action": "load_more_express", - "offset": "00", - "category": "29817", - "_ajax_nonce": "235111d38c"} - - res = requests.post(url, data=q_data, headers=DEFAULT_HEADERS) - posts = json.loads(res.text)['expressList'] + url = f'https://www.weiyangx.com/category/express' + res = requests.get(url, headers=DEFAULT_HEADERS) + res = Selector(res.text) + posts = res.css('script::text')[-4].extract().split('=')[-1] + posts = json.loads(posts) items = list(map(parse, posts)) return { 'title': f'快讯 - 未央网', diff --git a/rsshub/spiders/weiyangx/home.py b/rsshub/spiders/weiyangx/home.py new file mode 100644 index 0000000..fdba8a1 --- /dev/null +++ b/rsshub/spiders/weiyangx/home.py @@ -0,0 +1,31 @@ +import requests +import json +from parsel import Selector +from rsshub.utils import DEFAULT_HEADERS + +domain = 'https://www.weiyangx.com' + + +def parse(post): + item = {} + item['title'] = post['title'] + item['description'] = post['content'] + post_id = post['id'] + item['link'] = f'{domain}/{post_id}.html' + return item + + +def ctx(): + url = f'https://www.weiyangx.com/' + res = requests.get(url, headers=DEFAULT_HEADERS) + res = Selector(res.text) + posts = res.css('script::text')[-5].extract().split('=')[-1] + posts = json.loads(posts) + items = list(map(parse, posts)) + return { + 'title': f'快讯 - 未央网', + 'description': f'快讯 - 未央网', + 'link': f'{domain}/category/express', + 'author': f'hillerliao', + 'items': items + } diff --git a/rsshub/spiders/weiyangx/tag.py b/rsshub/spiders/weiyangx/tag.py index fb1382c..99753ea 100644 --- a/rsshub/spiders/weiyangx/tag.py +++ b/rsshub/spiders/weiyangx/tag.py @@ -1,28 +1,21 @@ -import requests -import json from rsshub.utils import DEFAULT_HEADERS +from rsshub.utils import fetch domain = 'https://www.weiyangx.com' def parse(post): item = {} - item['title'] = post['title'] - item['description'] = post['content'] - item['link'] = post['url'] - item['author'] = post['authorMeta'] + item['title'] = post.css('h2::text').extract_first() + item['description'] = post.css('p::text').extract_first() + item['link'] = post.css('a::attr(href)').extract_first() return item def ctx(category=''): - url = f'https://www.weiyangx.com/wp-admin/admin-ajax.php' - q_data = {"action": "home_load_more_news", - "postOffset": "00", - "tagId": category, - "_ajax_nonce": "1846edad4e"} - - res = requests.post(url, data=q_data, headers=DEFAULT_HEADERS) - posts = json.loads(res.text)['data'] + url = f'https://www.weiyangx.com/tag/{category}' + tree = fetch(url, headers=DEFAULT_HEADERS) + posts = tree.css('.category-post-node') items = list(map(parse, posts)) return { 'title': f'{category} - 文章 - 未央网',