实例——百度翻译

# -*- coding: UTF-8 -*-
import requests

print '1. 中译英'
print '2. 英译中'
while True:
    select = raw_input('请选择您需要的操作:')
    if select == '1':
        _from = 'zh'
        _to = 'en'
        break
    elif select == '2':
        _from = 'en'
        _to = 'zh'
        break
    else:
        print '输入有误,请重新输入!'
_query = raw_input('请输入您要查询的内容:')

url = 'http://fanyi.baidu.com/v2transapi'
data = {'from': _from,
        'to': _to,
        'query': _query,
        'transtype': 'realtime',
        'simple_means_flag': 3}
json = requests.post(url, data).json()
print json['trans_result']['data'][0]['result'][0][1]
原文地址:https://www.cnblogs.com/yestreenstars/p/5583792.html