White seek guidance: There is no way to get a constant From Data Baidu translation of the head file, how to think, to successfully access interface Baidu translation
import requests
import os
import json
os.chdir(r"H:\01\spyder")
url_fanyi = "https://fanyi.baidu.com/v2transapi?from=zh&to=en"
headers = {'user-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}
#发送语言识别请求
url_lang = "https://fanyi.baidu.com/langdetect"
lang_data = {'query': '你'}
#读取返回的json对象值
lang = requests.post(url_lang,data=lang_data,headers=headers)
jsontext = json.loads(lang.text)
jsontext['lan']
#发送翻译请求
#百度翻译这里data没有办法获取
fanyi_data = {
'from':jsontext['lan'] ,
'to': 'en',
'query': '你'
}
fanyi = requests.post(url_fanyi,data = fanyi_data,headers=headers)
-------------------------------------------- video learning little cakes Xianer 2020.2.26 -------------