【发布时间】:2019-11-03 15:26:51
【问题描述】:
我想从 subreddit 获取最新的帖子 ID。 Reddit 对此有基本的 api。你可以得到 json 所以我想提供数据并对其进行解码,但我有一个错误。
root@archi-sunucu:~/yusuf/www# python3 reddit.py
Traceback (most recent call last):
File "reddit.py", line 24, in <module>
json = json.loads(resp.text())
TypeError: 'str' object is not callable
root@archi-sunucu:~/yusuf/www# python3 reddit.py
我的代码:
url = "https://www.reddit.com/r/" + subreddit + "/" + feed + ".json?sort=" + feed + "&limit=6"
resp = requests.get(url, verify=False)
json = json.loads(resp.text())
print(json["data"]["children"][0]["data"]["id"])
感谢您的帮助...
【问题讨论】:
-
如果不能调用就不要调用了:
json.loads(resp.text) -
你读过我写的吗?
标签: json python-3.x python-requests