百度翻译请求的数据一般有sign值,而这个是js代码生成的,简单的方法是:手机版百度翻译,选择默认提示的post,地址https://fanyi.baidu.com/sug
data={‘kw’:‘输入的英文’}
import requests
import json
headers = { "User-Agent":"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Mobile Safari/537.36",
}
data = {
"kw": "hello",
}
r = requests.post("https://fanyi.baidu.com/sug",headers=headers,data=data)
jsonret = json.loads(r.content.decode())
print(jsonret['data'][0]['k'],jsonret['data'][0]['v'])