import requests
#代理IP
proxies = {'http': '111.231.115.150:8888'}
#请求头
headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"}
def youdaoApi(kw):
#POST提交表单数据
data={
'action':'FY_BY_REALTIME',
'client':'fanyideskweb',
'doctype':'json',
'from':'AUTO',
'i':kw,
'keyfrom':'fanyi.web',
'salt':'1530604758900',
'sign':'b1430ee6dec2abcf5eadb05b773f510a',
'smartresult':'dict',
'to':'AUTO',
'typoResult':'false',
'version':'2.1',
}
#url 去掉_o
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
#获取响应
response=requests.post(url,data=data,headers=headers,proxies=proxies)
#转json
result=response.json()['translateResult'][0][0]['tgt']
return result
if __name__ == '__main__':
kw=input("请输入:"+'\n')
result=youdaoApi(kw)
print(result)
有道山寨版
最新推荐文章于 2023-09-11 17:43:19 发布