import requests import json header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36'} url = 'https://fanyi.baidu.com/sug' word = input('想翻译啥:') data = {'kw':word} response = requests.post(url=url,data=data,headers=header) obj = response.json() name = word+'.html' fp = open(name,'w',encoding='UTF-8') json.dump(obj=obj,fp=fp,ensure_ascii=False) print('战斗结束')
爬去百度翻译,结合成文本