Created
May 10, 2021 02:17
-
-
Save EdisonLeeeee/aa9195ab0eac6a861b388aff1a5b5118 to your computer and use it in GitHub Desktop.
Youdao Translator with PyThon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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