Skip to content

Instantly share code, notes, and snippets.

@EdisonLeeeee
Created May 10, 2021 02:17
Show Gist options
  • Save EdisonLeeeee/aa9195ab0eac6a861b388aff1a5b5118 to your computer and use it in GitHub Desktop.
Save EdisonLeeeee/aa9195ab0eac6a861b388aff1a5b5118 to your computer and use it in GitHub Desktop.
Youdao Translator with PyThon
import json
import requests
def translate(word):
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null'
key = {
'type': "AUTO",
'i': word,
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"ue": "UTF-8",
"action": "FY_BY_CLICKBUTTON",
"typoResult": "true"
}
response = requests.post(url, data=key)
if response.status_code == 200:
list_trans = response.text
result = json.loads(list_trans)
return result['translateResult'][0][0]['tgt']
else:
print("ERROR!")
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment