首页 > 解决方案 > 在 Python 中获取 url 列表的标题

问题描述

我正在编写一个 Discord Bot,我想在音乐功能中显示队列。它总是发送网址,我无法将它们转换为网站的标题。该代码有效,但问题是如何将网址列表转换为标题。我的代码:

@client.command()
async def view(ctx):
    global queue

    #convert url to title
    html = request.urlopen(queue[0]).read().decode('utf8')
    html[:60]
    soup = BeautifulSoup(html, 'html.parser')
    title= soup.find('title')

    await ctx.send(f":page_facing_up: ・ Your queue: `{queue}`")

标签: pythondiscorddiscord.py

解决方案


推荐阅读