import json
import requests
url = 'http://fanyi.baidu.com/basetrans'
query = input("请输入要翻译的内容:")
post_data = {
'query': query,
'from': 'zh',
'to': 'en',
}
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Mobile Safari/537.36'
}
response = requests.post(url,data=post_data,headers=headers)
result = json.loads(response.text)
print('翻译结果:{}'.format(result['trans'][0]['dst']))
import requests
url = 'http://fanyi.baidu.com/basetrans'
query = input("请输入要翻译的内容:")
post_data = {
'query': query,
'from': 'zh',
'to': 'en',
}
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Mobile Safari/537.36'
}
response = requests.post(url,data=post_data,headers=headers)
result = json.loads(response.text)
print('翻译结果:{}'.format(result['trans'][0]['dst']))