很简单的东西,学会了可以试试换个接口
import requests
def crawl(wenzi):
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {'i': wenzi,
'from': 'AUTO',
'to': 'AUTO',
'smartresult': 'dict',
'client': 'fanyideskweb',
'doctype': 'json',
'version': '2.1',
'keyfrom': 'fanyi.web',
'action': 'FY_BY_REALTIME',
'typoResult': 'false'}
r = requests.post(url, data=data)
print(r)
answer = r.json()
print(answer)
result = answer['translateResult'][0][0]['tgt']
print('"'+ wenzi + '"的翻译结果:' + result + '\n')
crawl("你好")