|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小白求助,按着一本书上打的,可是报错了
- import requests
- import json
- def get_translate_date(word=None):
- url='http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
- Form_data= {'i':word,
- 'from':'AUTO',
- 'to':'AUTO',
- 'smartresult':'dict',
- 'client':'fanyideskweb',
- 'salt':'1525779321853',
- 'sign':'0ffa27b57b0924bdfe7d14f856493c2c',
- 'doctype':'json',
- 'version':'2.1',
- 'keyfrom':'fanyi.web',
- 'action':'FY_BY_REALTIME',
- 'typoResult':'false'}
- response = requests.post(url, data=payload)
- content = json.loads(response.text)
- print(content['translateResult'][0][0]['tgt'])
- if __name__ == '__main__':
- get_translate_date('略略略')
复制代码
报错内容:
D:\untitled\venv\Scripts\python.exe D:/untitled/test.py
Traceback (most recent call last):
File "D:/untitled/test.py", line 21, in <module>
get_translate_date('略略略')
File "D:/untitled/test.py", line 17, in get_translate_date
response = requests.post(url, data=payload)
NameError: name 'payload' is not defined
Process finished with exit code 1
http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule
把_o去掉试试
|
|