Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/mcbbs_news/mcbbs_news.py

32 lines
914 B
Python
Raw Normal View History

2022-01-19 14:41:31 +00:00
from bs4 import BeautifulSoup
2022-01-20 12:13:03 +00:00
2022-01-19 14:41:31 +00:00
from config import Config
from core.elements import Url
from core.utils import get_url
async def news():
api = 'https://www.mcbbs.net/forum-news-1.html'
webrender = Config('web_render')
2022-06-15 00:29:20 +00:00
if not webrender:
return
api = webrender + 'source?url=' + api
2022-01-19 14:41:31 +00:00
html = await get_url(api)
print(html)
bs = BeautifulSoup(html, 'html.parser')
results = bs.select('#threadlisttableid > tbody[id^="normalthread_"]')
res = []
if results is not None:
for i in results:
if len(res) == 5:
break
a = i.select_one('a.s.xst')
if not a.has_attr('style'):
continue
title = a.get_text()
url = Url('https://www.mcbbs.net/' + a.get('href'))
res += [{'count': len(res) + 1, 'title': title, 'url': url}]
return res
else:
return None