python - 如何访问推文对象的扩展 URL?
问题描述
基于 URL 的 Twitter API:https ://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/entities#urls
我想从推文的“实体”属性中的“url”属性中获取“expanded_url”属性。现在我有这个代码:
if post["entities"]["urls"]:
url = post["entities"]["urls"]
print(url)
它以这种格式打印一个数组:
[{'display_url': 'xxx', 'indices': [xx, xx], 'expanded_url': 'xxx', 'url': 'xxx'}]
我想得到'expanded_url',并尝试过url["expanded_url"]
,它只是抛出一个错误:
TypeError: list indices must be integers or slices, not str
有谁知道如何检索 url 属性的子属性?
解决方案
推荐阅读
- eclipse - Ubnutu:在 Eclipse IDE 中安装 lombok 显示错误“无法写入目录”,即使使用 sudo
- javascript - 如何在类组件中重用具有布尔状态的函数
- mdriven - 在多数据库租户 Web 应用程序中访问模型类的派生属性时出现问题
- mysql - 为什么对于 SQLCOM_UPDATE_MULTI,它用 lock_s (INNODB) 锁定其他表
- excel - 在 Excel 中记录更改(谁勾选了复选框、什么时间等)
- python - 如何访问kivymd主类中不同类的ID?
- python - 'numpy.float64' 对象不能被解释为整数,并且在 Python 中进行 ODE 求解
- zfs - Zpool 导入 - 一台或多台设备当前不可用
- xpath - Telegram 的即时视图:无法加载 .webp 和 .ico 图像
- python-3.x - 异常后继续 - Python