首页 > 解决方案 > 如何获取字典中的链接?

问题描述

@app.route('/<variable>')
def daily(variable):
    youtubeUrl = "https://www.youtube.com/results?search_query="+variable 
    search = SearchVideos(variable,offset=1,mode="json",max_results=1)
    y = json.loads(search.result())
    print(y)
    
    return redirect(youtubeUrl)

和我的输出; 在此处输入图像描述

我尝试在此输出中获取“链接”,但我写的内容没有用,我该怎么办?

标签: python

解决方案


youtube_url = y['search_result'][0]['link']

y是一个字典。在 dict 里面有一个由 key 指向的列表search_result。列表中的第一项是一个字典,其键名为link


推荐阅读