好友
阅读权限10
听众
最后登录1970-1-1
|
[mw_shl_code=python,true]import requests
import json
def get_translate_date(word=None):
url = 'https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
Form_date = {'i': word, 'from': 'AUTO', 'to': 'AUTO', 'smartresult': 'dict', 'client': 'fanyideskweb',
'salt': '16291842863437',
'sign': '10344d59de48aef99140f39226462fa0', 'lts': '1629184286343',
'bv': 'eda468fc64295ecf2810ab8a672c2db1', 'doctype': ' json',
'version': ' 2.1', 'keyfrom': 'fanyi.web', 'action': 'FY_BY_REALTlME'}
a = requests.post(url, data=Form_date)
print(a.text)
content = json.loads(a.text)
print(content['translateResult'][0][0]['tgt'])
if __name__ == '__main__':
word = input("请输入你要翻译的文字:")
get_translate_date(word)
[/mw_shl_code]
G:\爬虫\Scripts\python.exe C:/Users/Administrator/PycharmProjects/pythonProject1/爬虫2.py
请输入你要翻译的文字:詹三
{"errorCode":50}
Traceback (most recent call last):
File "C:\Users\Administrator\PycharmProjects\pythonProject1\爬虫2.py", line 20, in <module>
get_translate_date(word)
File "C:\Users\Administrator\PycharmProjects\pythonProject1\爬虫2.py", line 15, in get_translate_date
print(content['translateResult'][0][0]['tgt'])
KeyError: 'translateResult'
进程已结束,退出代码为 1 |
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|