Traceback (most recent call last):
File "E:/Code/Python/爬虫/post.py", line 25, in <module>
get_translate_data('我爱数据')
File "E:/Code/Python/爬虫/post.py", line 23, in get_translate_data
print(content['translateResult'][0][0]['tgt'])
KeyError: 'translateResult'
URL错误
有道翻译的接口不是:
http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule
而是:
http://fanyi.youdao.com/translate
修改URL即可
参考:https://blog.csdn.net/crystal_lyp/article/details/100055876