我需要从这个JSON对象中提取一个视频文件。例如,我有两个Episode,我想拉 * Episode 1 *,并下载它。我该怎么做呢?
{"list ":{"1":{" episode ":1、"名称":null," uuid ":"95cbd36e-789e-11ec-ae92 - 0242ac120002","created_timestamp":1571078646,“预览”:null,"跳过":{"opening ":[],"结束":[]}," hls ":{" fhd":"/videos/media/ts/8499/1/1080/9186f5d125c799f16965a9b3a38a2c42.m3u8 "," hd ":"/videos/media/ts/8499/1/720/5a310e07f181fb31a7d9b69f7a62b4c8.m3u8","sd":"/videos/media/ts/8499/1/480/0fc60668a8713fbe55bb0cec4b7dc0d4.m3u8 "}},"2":{"episode ":2、"名称":null," uuid ":" 95cbd3e3 - 789e-11ec-ae92 - 0242ac120002","created_timestamp":1571722736,“预览”:null,"跳过":{" opening ":[],"结束":[]}," hls":{" fhd":"/videos/media/ts/8499/2/1080/314fd5a58d5d08be401be695e5a37e03.m3u8"," hd":"/videos/media/ts/8499/2/720/84ce5fdff2cb0fca90db72f900e94359.m3u8"," sd":"/videos/media/ts/8499/2/480/4f4e483ac65fb1c24ea90dd1d053c128.m3u8 "}}
我找不到任何例子,或者知道如何做到这一点的人。
我尝试做某事:
import requests
user_input = input("Enter anime title: ")
url = f'https://api.anilibria.tv/v3/title/search?search={user_input}'
res = requests.get(url)
res.raise_for_status()
data = res.json()
titles_and_links = []
for entry in data['list']:
try:
title = entry['names']['ru']
video_link = entry['episode'][0]['fhd']
data_item = {
'title': title,
'video_link': video_link
}
titles_and_links.append(data_item)
except KeyError as e:
print(f"Skipping entry due to missing data: {e}")
for item in titles_and_links:
print("Title:", item['title'])
print("Video Link:", item['video_link'])
print()
1条答案
按热度按时间6ojccjat1#
IIUC,你想从名为
list
的字典中获取情节1
(顺便说一句,非常不幸的命名):打印(例如):