requests实战之破解百度翻译
import json import requests if __name__ == '__main__': post_url = 'https://fanyi.baidu.com/sug' # 进行UA伪装 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' } # post请求参数处理(同get请求一致) kw = input("enter a word: ") data ={ 'kw':kw } res = requests.post(url=post_url,data=data,headers= headers) dic_obj = res.json() # 返回obj(如果确认响应数据是json类型的,才可以使用json()方法) print(dic_obj) # 持久化存储 filename = kw fp = open(filename+'.json','w',encoding='utf-8') json.dump(dic_obj,fp=fp,ensure_ascii=False) print("over")
作者:华王
博客:https://www.cnblogs.com/huahuawang/