discord.py“NoneType”对象没有属性“find”

2024-07-02 13:19:48 发布

您现在位置:Python中文网/ 问答频道 /正文

@client.command()
async def csgonow(ctx):
    url = "https://steamdb.info/app/730/graphs/" 
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            soupObject = BeautifulSoup(await response.text(), "html.parser")
            online = soupObject.find(class_='home-stats').find('li').find('strong').get_text()
            await ctx.send(online + ' players are playing this game at the moment')

当我使用命令!R csgonow时,我得到以下错误:

 discord.ext.commands.errors.CommandInvokeError: Command raised an exception:
  AttributeError: 'NoneType' object has no attribute 'find'

我该如何解决这个问题


Tags: textclienturlgetasyncresponsesessionas
1条回答
网友
1楼 · 发布于 2024-07-02 13:19:48

您可以使用CSS选择器:

@client.command()
async def csgonow(ctx):
    url = "https://steamdb.info/app/730/graphs/"
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            soupObject = BeautifulSoup(await response.text(), "html.parser")
            online = soupObject.select_one('.app-chart-numbers-big > li:nth-child(2) > strong:nth-child(1)').text
            await ctx.send(f' {online} players are playing this game at the moment')

相关问题 更多 >