帝王谷资源网 Design By www.wdxyy.com

初期操作

"htmlcode">

Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Content-Length: 252
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: OUTFOX_SEARCH_USER_ID=-1927650476@223.97.13.65; OUTFOX_SEARCH_USER_ID_NCOO=1897197670.972445; JSESSIONID=aaalvPunK-sv2fyR-UjEx; ___rl__test__cookies=1612924426799
Host: fanyi.youdao.com
Origin: http://fanyi.youdao.com
Referer: http://fanyi.youdao.com/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36
X-Requested-With: XMLHttpRequest

再就是params参数,变化的是salt、sign、lts,尝试后发现lts可有可无,所以变化的只有salt、sign两项。

i: 你好
from: AUTO
to: AUTO
smartresult: dict
client: fanyideskweb
salt: 16129244361391
sign: 2820759b6e54f25e0aa94e185e2265e3
lts: 1612924436139
bv: 3da01a09873456cfb5dba05f2124b148
doctype: json
version: 2.1
keyfrom: fanyi.web
action: FY_BY_REALTlME

分析salt、sign

全局搜索sign,结果中有fanyi.min.js文件,双击进入,然后右键选择'Open in Source panel',搜索'sign',找到如下代码:

define("newweb/common/service", ["./utils", "./md5", "./jquery-1.7"], function(e, t) {
 var n = e("./jquery-1.7");
 e("./utils");
 e("./md5");
 var r = function(e) {
  var t = n.md5(navigator.appVersion)
   , r = "" + (new Date).getTime()
   , i = r + parseInt(10 * Math.random(), 10);
  return {
   ts: r,
   bv: t,
   salt: i,
   sign: n.md5("fanyideskweb" + e + i + "Tbh5E8=q6U3EXe+&L[4c@")
  }
 };

"htmlcode">

import hashlib
import random
import time
import requests


def get_data():
 r = str(round(time.time() * 1000))
 salt = r + str(random.randint(0, 9))

 content = '你好'

 data = "fanyideskweb" + content + salt + "Tbh5E8=q6U3EXe+&L[4c@"
 sign = hashlib.md5()

 sign.update(data.encode("utf-8"))

 sign = sign.hexdigest()
 # print(len(sign))
 # print(sign)
 return content, salt, sign


def send_request(content, salt, sign):
 url = 'http://fanyi.youdao.com/translate_o"text-align: center">python 实现有道翻译功能

以上就是python 实现有道翻译的详细内容,更多关于python 有道翻译的资料请关注其它相关文章!

标签:
python,翻译,python,有道翻译

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com