鱼C论坛

 找回密码
 立即注册
查看: 2190|回复: 4

[已解决]有道翻译

[复制链接]
发表于 2022-7-4 17:02:53 | 显示全部楼层 |阅读模式
9鱼币
ssx={
    'Accept':'application/json,text/javascript,*/*;q=0.01'
}
url2="http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom="
s=input("ss")
dat={
    "kw":s
}
ss=requests.post(url2,data=dat,headers=ssx)
print(ss.text)

麻烦大佬看一下
对应的翻译不显示
最佳答案
2022-7-4 17:02:54
import requests
import hashlib
import random
import time

print("1.中>>英\n2.英>>中")
while True:
    mode = int(input("请输入翻译模式:"))
    if mode == 1:
        mFrom = "zh-CHS"
        mTo = "en"
        break
    elif mode == 2:
        mFrom = "en"
        mTo = "zh-CHS"
        break
    else:
        print("输入非法,请重新输入")

text = input("请输入待翻译的内容:")

url = "https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"

headers = {
    "Cookie":"OUTFOX_SEARCH_USER_ID=-1347179823@10.110.96.157; OUTFOX_SEARCH_USER_ID_NCOO=254810992.67636687; ___rl__test__cookies=1657200006595",
    "Referer":"https://fanyi.youdao.com/",
    "User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
}

lts = str(int(time.time()*1000))
salt = lts + str(random.randint(0,10))
sign_str = "fanyideskweb" + text + salt + "Ygy_4c=r#e#4EX^NUGUc5"
m = hashlib.md5(sign_str.encode())
sign = m.hexdigest()

data = {
    "i":text,
    "from":mFrom,
    "to":mTo,
    "smartresult":"dict",
    "client":"fanyideskweb",
    "salt":salt,
    "sign":sign,
    "lts":lts,
    "bv":"a16a6033635b516a9006542112cdda8f",
    "doctype":"json",
    "version":"2.1",
    "keyfrom":"fanyi.web",
    "action":"FY_BY_CLICKBUTTION"
}

response = requests.post(url,headers=headers,data=data)
if response.status_code == 200:
    resalut = eval(response.text)["translateResult"][0][0]["tgt"]
    print("翻译结果:",resalut)
else:
    print("翻译失败")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-7-4 17:02:54 | 显示全部楼层    本楼为最佳答案   
import requests
import hashlib
import random
import time

print("1.中>>英\n2.英>>中")
while True:
    mode = int(input("请输入翻译模式:"))
    if mode == 1:
        mFrom = "zh-CHS"
        mTo = "en"
        break
    elif mode == 2:
        mFrom = "en"
        mTo = "zh-CHS"
        break
    else:
        print("输入非法,请重新输入")

text = input("请输入待翻译的内容:")

url = "https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"

headers = {
    "Cookie":"OUTFOX_SEARCH_USER_ID=-1347179823@10.110.96.157; OUTFOX_SEARCH_USER_ID_NCOO=254810992.67636687; ___rl__test__cookies=1657200006595",
    "Referer":"https://fanyi.youdao.com/",
    "User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
}

lts = str(int(time.time()*1000))
salt = lts + str(random.randint(0,10))
sign_str = "fanyideskweb" + text + salt + "Ygy_4c=r#e#4EX^NUGUc5"
m = hashlib.md5(sign_str.encode())
sign = m.hexdigest()

data = {
    "i":text,
    "from":mFrom,
    "to":mTo,
    "smartresult":"dict",
    "client":"fanyideskweb",
    "salt":salt,
    "sign":sign,
    "lts":lts,
    "bv":"a16a6033635b516a9006542112cdda8f",
    "doctype":"json",
    "version":"2.1",
    "keyfrom":"fanyi.web",
    "action":"FY_BY_CLICKBUTTION"
}

response = requests.post(url,headers=headers,data=data)
if response.status_code == 200:
    resalut = eval(response.text)["translateResult"][0][0]["tgt"]
    print("翻译结果:",resalut)
else:
    print("翻译失败")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-7-4 18:28:37 | 显示全部楼层
import urllib.request
import urllib.parse

s = input("ss")
url = 'https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {}
data['i'] = s
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '16377384094512'
data['sign'] = '85efcb3000263b62f1398ac5a8c4da72'
data['lts'] = '1637738409451'
data['bv'] = 'b0ff5d17f404993192085bf8b1e93587'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_REALTlME'
data = urllib.parse.urlencode(data).encode('utf-8')

response = urllib.request.urlopen(url, data)
html = response.read().decode('utf-8')

print(html)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-7-5 02:40:30 | 显示全部楼层
import requests
import hashlib
import time
import random
from jsonpath import jsonpath
import tkinter as tk
class FanYi:
    def __init__(self, word, country):
        self.url = 'https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
            'Referer': 'https://fanyi.youdao.com/',
            'Cookie': 'OUTFOX_SEARCH_USER_ID=1907954952@182.203.147.49; OUTFOX_SEARCH_USER_ID_NCOO=2032702153.1070416; fanyi-ad-id=306808; fanyi-ad-closed=1; ___rl__test__cookies=1654931146702',
        }
        self.word = word
        self.country = country
    def run(self):
        lts = int(time.time()*1000)
        salt = str(lts) + str(random.randint(0, 9))
        sign = hashlib.md5(("fanyideskweb" + self.word + salt + "Ygy_4c=r#e#4EX^NUGUc5").encode()).hexdigest()
        data = {
            'i': self.word,
            'from': 'zh-CHS',
            'to': self.country,
            'smartresult': 'dict',
            'client': 'fanyideskweb',
            'salt': salt,
            'sign': sign,
            'lts': lts,
            'bv': '85618492e851e16ca0a03b8e100fdddb',
            'doctype': 'json',
            'version': '2.1',
            'keyfrom': 'fanyi.web',
            'action': 'FY_BY_REALTlME'
        }
        response = requests.post(self.url, headers=self.headers, data=data).json()
        text = jsonpath(response, '$..tgt')[0]
        return text
root = tk.Tk()
root.title('简易小翻译')
root.geometry('300x150')
L1 = tk.Label(root, text='请输入要翻译的内容:', font=('宋体', 14)).pack(anchor='nw')
txt = tk.StringVar()
txt.set('')
E1 = tk.Entry(root, textvariable=txt, width=32, bd=3).pack(anchor='nw')
L2 = tk.Label(root, text='翻译后的内容:', font=('宋体', 14)).pack(anchor='nw')
txt2 = tk.StringVar()
def fun1():
    word = txt.get()
    test = FanYi(word, 'en')
    res = test.run()
    txt2.set(res)
def fun2():
    word = txt.get()
    test = FanYi(word, 'ja')
    res = test.run()
    txt2.set(res)
def fun3():
    word = txt.get()
    test = FanYi(word, 'ko')
    res = test.run()
    txt2.set(res)
def fun4():
    word = txt.get()
    test = FanYi(word, 'ru')
    res = test.run()
    txt2.set(res)
L3 = tk.Label(root, textvariable=txt2, font=('宋体', 14)).pack(anchor='nw')
B1 = tk.Button(root, text='中->英', command=fun1).pack(anchor='nw')
B2 = tk.Button(root, text='中->日', command=fun2).place(x=60, y=100)
B3 = tk.Button(root, text='中->韩', command=fun3).place(x=120, y=100)
B4 = tk.Button(root, text='中->俄', command=fun4).place(x=180, y=100)
root.mainloop()
-----------------------------------------------------------------------------------------------
有道翻译post请求里的form表单中的salt, sign, lts等几个参数也是随着每次请求不断变化的, 需要做逆向处理,
lts和salt跟时间戳有关, sign则是采用了MD5加密
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-7-7 19:32:00 | 显示全部楼层
有加密的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-17 16:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表