消失了几天,我又回来了。
昨晚看了个关于酷Q机器人的视频,感觉挺好玩的,然后就试了下。
这个爬取的是百度的搜索风云榜的信息。
import parsel
import requests
from aiocqhttp import CQHttp, Event
bot = CQHttp()
async def get_redian():
url = 'http://top.baidu.com/buzz?b=1&c=513&fr=topbuzz_b341_c513'
response = requests.get(url)
response.encoding = 'gb2312'
response = parsel.Selector(response.text)
titles = response.xpath("//td[@class='keyword']/a[@class='list-title']/text()").extract()[:10]
shuchu = ''
for index, i in enumerate(titles):
shuchu += f'【{index + 1}】{i}
'
return shuchu
@bot.on_message('group')
async def _(event: Event):
msg = event.message.split(' ')
if msg[0] == '实时热点':
await bot.send_group_msg(group_id=event.group_id, message=await get_redian())
bot.run(host='127.0.0.1', port=8080)
评论 (0)