1.使用requests模块获取这个json文件http://java-api.super-yx.com/html/hello.json
2.将获取到的json转为dict
3.将dict保存为hello.json文件
4.用io流写一个copy(src,dst)函数,复制hello.json到C:\hello.json
import json
import shutilimport requests
#使用requests模块获取这个json文件http://java-api.super-yx.com/html/hello.json
#将获取到的json转为dict
data_dict={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) ""AppleWebKit/537.36 (KHTML, like Gecko)"" Chrome/126.0.0.0 Safari/537.36"}
response = requests.get("http://java-api.super-yx.com/html/hello.json",headers=data_dict)
print(response)
print(response.text)
#将dict保存为hello.json文件
with open('hello.josn','w',encoding='utf-8') as f:json.dump(data_dict,f,ensure_ascii=False,indent=4)
#用io流写一个copy(src,dst)函数,复制hello.json到C:\hello.json
def copy(src,dst):with open(src,'rb') as src_file:with open(dst,'wb') as dst_file:shutil.copyfileobj(src_file,dst_file)copy('hello.josn',r'D:\hello.josn')
代码运行结果