【发布时间】:2025-12-17 15:55:01
【问题描述】:
我正在使用 Beautiful Soup 4 将网页中的一些文本抓取到 Discord 机器人中。
@commands.command(hidden=True)
async def roster(self):
"""A script using BS4."""
url = "http://www.clandestine.pw/roster.html"
async with aiohttp.get(url) as response:
soupObject = BeautifulSoup(await response.text(), "html.parser")
try:
txt = soupObject.find("font", attrs={'size': '4'}).get_text()
await self.bot.say(txt)
except:
await self.bot.say("Not found!")
运行命令,这将返回“ThaIIen”(应该如此)。如果我只是将find 更改为find_all,它会返回“未找到!”为什么?这不应该返回文档中每个字体大小为 4 的文本吗?
【问题讨论】:
标签: python python-2.7 web-scraping beautifulsoup