一、代码展示:
import requests
import json
post_url='https://fanyi.baidu.com/sug'
headers={
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0'
}
data={
'kw':'dog'
}
#请求发送
response=requests.post(url=post_url,data=data,headers=headers)
#如果确认相应类型是json才可
dic_obj=response.json()
#持久化储存
fp=open('./dog.json','w',encoding='utf-8')
json.dump(dic_obj,fp=fp,ensure_ascii=False)
print('over!!!')
二、结果展示
{"errno": 0, "data": [{"k": "dog", "v": "n. 狗; 蹩脚货; 丑女人; 卑鄙小人 v. 困扰; 跟踪"}, {"k": "DOG", "v": "abbr. Data Output Gate 数据输出门"}, {"k": "doge", "v": "n. 共和国总督"}, {"k": "dogm", "v": "abbr. dogmatic 教条的; 独断的; dogmatism 教条主义; dogmatist"}, {"k": "Dogo", "v": "[地名] [马里、尼日尔、乍得] 多戈; [地名] [韩国] 道高"}]}