【发布时间】:2017-07-27 21:19:18
【问题描述】:
首先我会说我是 Python 新手。我一直在用 discord.py 和 Beautiful Soup 4 构建一个 Discord 机器人。这就是我所在的位置:
@commands.command(hidden=True)
async def roster(self):
"""Gets a list of CD's members"""
url = "http://www.clandestine.pw/roster.html"
async with aiohttp.get(url) as response:
soupObject = BeautifulSoup(await response.text(), "html.parser")
try:
text = soupObject.find_all("font", attrs={'size': '4'})
await self.bot.say(text)
except:
await self.bot.say("Not found!")
现在,我尝试以多种不同的方式使用get_text() 来去除这段代码中的括号和 HTML 标记,但每次都会引发错误。我怎样才能实现这一点或将这些数据输出到数组或列表中,然后只打印纯文本?
【问题讨论】:
-
你用的是哪个版本的python和美汤?我假设它 >= python 3.5 给出了异步等待语法
标签: python beautifulsoup bs4 discord