地址 :https://fanyi-api.baidu.com/api/trans/product/desktop
注册时候界面:
接口文档:
https://api.fanyi.baidu.com/doc/21
需要注意的是。高级认证每月前200W个字符免费,后续需要收费,不要以为22W字符很多,我测试了3-4篇英文 文章翻译就6W字符了:
接口:
请求方式: 可使用 GET 或 POST 方式,如使用 POST 方式,Content-Type 请指定为:application/x-www-form-urlencoded
字符编码:统一采用 UTF-8 编码格式
大致如下:
def BD_trans(mstr):
url = 'https://fanyi-api.baidu.com/api/trans/vip/translate'
appid = '****'
salt ='**'#随便写
to = 'zh'
key= '***'
sign = domd5(appid+mstr+salt+key)
posts = 'q={}&from=auto&to={}&appid={}&salt={}&sign={}'.format(parse.quote(mstr),to,appid,salt,sign)
res = requests.post(url,data=posts,headers={'Content-Type':'application/x-www-form-urlencoded'}).json()
return (res["trans_result"][0]["dst"])
其中key和appid在页面中查看:
结果:
本文标题: | [python]百度の翻译接口测试 – vulsee.com |
本文链接: (转载请附上本文链接) | https://vulsee.com/archives/vulsee_2022/0712_16552.html |