python - 如何获取字典中的链接?
问题描述
@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)
我尝试在此输出中获取“链接”,但我写的内容没有用,我该怎么办?
解决方案
youtube_url = y['search_result'][0]['link']
y
是一个字典。在 dict 里面有一个由 key 指向的列表search_result
。列表中的第一项是一个字典,其键名为link
推荐阅读
- django - 在每行中使用单选按钮呈现表单的推荐方法
- apache-kafka - 测量 Kafka 生产者批次的实现压缩率
- python - 如何使用 PIL 显示shutil数据
- javascript - Service Worker 可以访问浏览器缓存吗?
- phaser-framework - Phaser 的新功能:当 cursor.up.isDown 时,无法更改玩家的 body.velocity.y。有什么东西挡住了吗?
- python - 什么都不提供时,LassoCV 中的参数选择如何工作?
- module - 来自 Bot Framework 中 Ms Teams 的任务模块调用
- c# - 带有命名元组的 JavaScriptSerializer
- python - 如何将用户输入添加到列表并能够看到它?
- google-cloud-functions - 谷歌云功能激活