编程语言
首页 > 编程语言> > Python练习009

Python练习009

作者:互联网

题目:利用ajax请求破解百度翻译
代码:

import requests
import argparse

headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64)\
           AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280\
           .88 Safari/537.36 Edg/87.0.664.60'}
url = 'https://fanyi.baidu.com/sug'
parser = argparse.ArgumentParser()
parser.add_argument('-i',type = str, default = 'hello')
arg = parser.parse_args()
i = arg.i
data = {'kw': i}

translation = requests.post(url = url,data = data, headers = headers).json()
print(translation)

标签:parser,headers,Python,练习,url,537.36,009,data,translation
来源: https://blog.csdn.net/IMDASHUAI/article/details/111397399