网址

https://fanyi.youdao.com/index.html#/

接口

https://dict.youdao.com/webtranslate

Python代码

# -*- coding: utf-8 -*-
# @Author: Null119 微信公众号/网站:治廷君
# @Desc: { 有道翻译 }
# @Date: { 2022-12-16 }

import requests
import time
import hashlib
import json,jsonpath
import execjs

ctx = execjs.compile(open('./youdao.js',encoding='utf-8').read())

def getdata(words):
    s = requests.session()
    s.get('http://fanyi.youdao.com/')
    headers={
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
        'Referer': 'http://fanyi.youdao.com/'
    }
    api = 'http://dict.youdao.com/webtranslate?smartresult=dict&smartresult=rule'
    ts = str(int(time.time()*1000))
    enstr=f'client=fanyideskweb&mysticTime={ts}&product=webfanyi&key=fsdsogkndfokasodnaso'
    sign = hashlib.md5(enstr.encode(encoding='utf-8')).hexdigest()
    print('sign:',sign)
    postdata = {
        'i': words,
        'from': 'AUTO',
        'to': 'AUTO',
        'dictResult':'true',
        'keyid':'webfanyi',
        'sign': sign,
        'client': 'fanyideskweb',
        'product':'webfanyi',
        'appVersion':'1.0.0',
        'vendor':'web',
        'pointParam':'client,mysticTime,product',
        'mysticTime': ts,
        'keyfrom': 'fanyi.web',
    }
    html =s.post(url=api,data=postdata,headers=headers)
    enhtml=html.text
    print('Response:',enhtml)
    endata = str(ctx.eval('decrypt("' + enhtml + '")'))
    print('Decrypt:',endata)
    tgt = jsonpath.jsonpath(json.loads(endata),'$..tgt')
    result=''
    for i in tgt:
        result = result + i + ' , '
    return '%s : %s' % (words , result[0:-3])

if __name__ == '__main__':
    print(getdata('happy'))

JS代码

请输入暗号查看内容(暗号有效期3天,全站通用)
请关注本站微信公众号,回复“暗号”获取。在微信里搜索公众号“治廷君”或者“ztkjgzs”或者微信扫描右侧二维码关注本站微信公众号。
如果觉得我的文章对你有用,请随意赞赏