打开字幕
打开开发者工具,在 filter 中输入 subtitle,查看预览中的响应
拿到请求 url
import requests | |
url = 'https://i0.hdslb.com/bfs/ai_subtitle/prod/901443427858625520cc36f6c6f9cfd8b3dfc56a6c562d65c3' | |
responce = requests.get(url=url) | |
print(responce.status_code) # 200 则表示获取成功 | |
import ast | |
# 将字符串转换成字典 | |
user_dict = ast.literal_eval(responce.text) | |
body = user_dict['body'] | |
content = '' | |
for i in range(len(body)): | |
# 拼接内容 | |
content += body[i]['content'] + ' ' | |
if i % 80 == 0 and i != 0: | |
content += '\n\n' | |
# 写入文件 | |
with open('test.md', 'w', encoding='utf-8') as f: | |
f.write(content) |