折腾:
【未解决】Python代码模拟google翻译把中文翻译为英文
期间,本以为已经写好模拟google翻译的python代码了。
结果换了个语言,换了要翻译的内容,结果发现tk值就变了,旧tk值就无效了。
所以只能想办法搞清楚生成tk参数的逻辑,才能用代码去模拟。
要翻译内容:test translate logic
英文-》中文
此时tk值:389397.220291

那接着去分析,何处生成这个值的

很明显,只能搜出一个,也就是之前知道的url:
1 | https: / / translate.google.cn / translate_a / single?client = webapp&sl = en&tl = zh - CN&hl = zh - CN&dt = at&dt = bd&dt = ex&dt = ld&dt = md&dt = qca&dt = rw&dt = rm&dt = ss&dt = t&pc = 1 &otf = 1 &ssel = 0 &tsel = 0 &kc = 1 &tk = 389397.220291 &q = test % 20translate % 20logic |
即:
https://translate.google.cn/translate_a/single
没啥帮助,不知道具体哪里生成的。
看来要去找tk了。
结果搜出来东西太多。
搜 tk=
搜出来不是太多

去分别看看
1 2 3 | https: / / apis.google.com / _ / scs / abc - static / _ / js / k = gapi.gapi.en. 7kWSr24wXFc .O / m = gapi_iframes,googleapis_client,plusone / rt = j / sv = 1 / d = 1 / ed = 1 / rs = AHpOoo - i9r7IbCTUQfJ0v - FPhRKRS8aihQ / cb = gapi.loaded_0 var ok,nk,uk,vk,pk,sk,qk,wk,rk;_.tk = function(){ if (nk){var a = new _.ke.Uint32Array( 1 );ok.getRandomValues(a);a = Number( "0." + a[ 0 ])} else a = pk,a + = parseInt(qk.substr( 0 , 20 ), 16 ),qk = rk(qk),a / = sk + Math. pow ( 16 , 20 ); return a};ok = _.ke.crypto;nk = ! 1 ;uk = 0 ;vk = 0 ;pk = 1 ;sk = 0 ;qk = " ";wk=function(a){a=a||_.ke.event;var b=a.screenX+a.clientX<<16;b+=a.screenY+a.clientY;b*=(new Date).getTime()%1E6;pk=pk*b%sk;0<uk&&++vk==uk&&_.ye(_.ke," mousemove ",wk," remove "," de")};rk = function(a){var b = new _.Kh;b.IE(a); return b.Pg()}; |
-》有点可能,像function去计算出来的?
以及:
1 2 3 | https: / / www.gstatic.cn / inputtools / js / ita / inputtools_1.js a.metaKey;this.G = lk?a.metaKey:a.ctrlKey;this.B = a;a.defaultPrevented&&this.preventDefault()}},pk = function(a){ return (nk? 0 = = a.B.button:a. type = = n?! 0 :!!(a.B.button&ok[ 0 ]))&&!(N&&lk&&a.ctrlKey)},rk = function(a,b,c,d,e){this.listener = a;this.A = null;this.src = b;this. type = c;this.capture = !!d;this.ma = e;this.key = + + qk;this.hd = this.wd = ! 1 },sk = function(a){a.hd = ! 0 ;a.listener = null;a.A = null;a.src = null;a.ma = null},tk = function(a){this.src = a;this.A = {};this.B = 0 },vk = function(a,b,c,d,e,g){var h = b.toString();b = a.A[h];b||(b = a.A[h] = |
不是太像:只是赋值
1 2 3 | https: / / www.gstatic.com / og / _ / js / k = og.qtm.en_US.D7UMNFi9kB0.O / rt = j / m = q_d,qmd,qcwid,qmutsd,qapid / exm = qaaw,qabr,qadd,qaid,qalo,qebr,qein,qhaw,qhbr,qhch,qhga,qhid,qhin,qhlo,qhmn,qhpc,qhpr,qhsf,qhtb,qhtt / d = 1 / ed = 1 / rs = AA2YrTt_kg - hfAJB9XubfvSn4sJw - qSM8A var sk,uk,wk,xk,zk,Ak,Ck,Dk,Ik;sk = function(a){ if (_.Aa(a)){ for (var c = Array(a.length),d = 0 ;d<a.length;d + + ){var e = a[d];null! = e&&(c[d] = "object" = = typeof e?sk(e):e)} return c} if (_.sc&&a instanceof Uint8Array) return new Uint8Array(a);c = {}; for (d in a)e = a[d],null! = e&&(c[d] = "object" = = typeof e?sk(e):e); return c};_.tk = function(a){ return new a.constructor(sk(a.tb()))};uk = function(a,c){a.f = c;a.Hb&&a.qc?(a.stop(),a.start()):a.Hb&&a.stop()}; |
也有点像:
1 | _.tk= function (a){ return new a.constructor(sk(a.tb()))}; |
-》调用别的函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | https: / / translate.google.cn / translate / releases / twsfe_w_20191118_RC00 / r / js / translate_m_zh - CN.js new Bi(this.g.Y());Mg(this,this.b);G(this.b, "tick" ,Ib(tk(this,m)),! 1 ,this);this.w = new Bi( 6E5 );Mg(this,this.w);G(this.w, "tick" ,Ib(tk(this,m)),! 1 ,this);this.C||this.w.start();this.Z||(G(Wf(), "beforeunload" ,this.o,! 1 ,this),G(Wf(), "unload" ,this.o,! 1 ,this),G(document, "pagehide" ,this.o,! 1 ,this))};t(uk,J);var tk = function(a,b){ return b?function(){b().then(a.flush.bind(a))}:a.flush};uk.prototype.T = function(){this.o();uk.D.T.call(this)}; sr:[ "sr-t-i0-handwrit" ],su:[ "su-t-i0-handwrit" ],sv:[ "sv-t-i0-handwrit" ],sw:[ "sw-t-i0-handwrit" ],ta:[ "ta-t-i0-handwrit" ],te:[ "te-t-i0-handwrit" ],tg:[ "tg-t-i0-handwrit" ],th:[ "th-t-i0-handwrit" ],tl:[ "fil-t-i0-handwrit" ],tr:[ "tr-t-i0-handwrit" ],uk:[ "uk-t-i0-handwrit" ],ur:[ "ur-t-i0-handwrit" ],uz:[ "uz-t-i0-handwrit" ],vi:[ "vi-t-i0-handwrit" ],xh:[ "xh-t-i0-handwrit" ], "zh-CN" :[ "zh-t-i0-handwrit" ],zu:[ "zu-t-i0-handwrit" ]};var Lk = function(a){hf(this,a, - 1 ,null)};t(Lk,df);Lk.prototype.Nd = function(){ return jf(this, 1 )};Lk.prototype.fb = function(){ return jf(this, 4 )};var Mk = function(a){hf(this,a, - 1 ,null)};t(Mk,df);var Ok = function(a){hf(this,a, - 1 ,null)};t(Ok,df);var Pk = function(a){hf(this,a, - 1 ,null)};t(Pk,df);var Rk = function(a){hf(this,a, - 1 ,Qk)};t(Rk,df);var Qk = [ 1 ];var Sk = function(a){hf(this,a, - 1 ,null)};t(Sk,df);var Tk = function(a){hf(this,a, - 1 ,null)};t(Tk,df);var Uk = function(a){hf(this,a, - 1 ,null)};t(Uk,df);var Vk = function(a){hf(this,a, - 1 ,null)};t(Vk,df);var Wk = function(a){hf(this,a, - 1 ,null)};t(Wk,df);Wk.prototype.Ua = function(){ return jf(this, 1 )};var Xk = function(a){hf(this,a, - 1 ,null)};t(Xk,df);var Zk = function(a){hf(this,a, - 1 ,Yk)};t(Zk,df);var Yk = [ 1 , 3 , 4 ];var $k = function(a){hf(this,a, - 1 ,null)};t($k,df);var al = function(){var a = new $k; return A(a, 1 , 1 )};var bl = function(a){hf(this,a, - 1 ,null)};t(bl,df);bl.prototype.Kb = function(){ return jf(this, 1 )};var cl = function(a){hf(this,a, - 1 ,null)};t(cl,df);var el = function(a){hf(this,a, - 1 ,dl)};t(el,df);var dl = [ 1 ];el.prototype.fb = function(){ return jf(this, 5 )};var fl = function(a){hf(this,a, - 1 ,null)};t(fl,df);var hl = function(a){hf(this,a, - 1 ,gl)};t(hl,df);var gl = [ 2 ];var il = function(a){hf(this,a, - 1 ,null)};t(il,df);var jl = function(){var a = new il; return A(a, 1 , 3 )};var kl = function(a){hf(this,a, - 1 ,null)};t(kl,df);var ll = function(a){hf(this,a, - 1 ,null)};t(ll,df);ll.prototype.qf = function(){ return jf(this, 4 )};ll.prototype.Li = function(){ return null! = jf(this, 4 )};var ml = function(a){hf(this,a, - 1 ,null)};t(ml,df);var ol = function(a){hf(this,a, - 1 ,nl)};t(ol,df);var nl = [ 3 , 4 ];var ql = function(a){hf(this,a, - 1 ,pl)};t(ql,df);var pl = [ 3 ];ql.prototype.Be = function(){ return jf(this, 1 )};var sl = function(a){hf(this,a, - 1 ,rl)};t(sl,df);var rl = [ 2 ];var ul = function(a){hf(this,a, - 1 ,tl)};t(ul,df);var tl = [ 26 , 80 ];ul.prototype.Ce = function(){ return jf(this, 1 )};ul.prototype.Be = function(){ return jf(this, 53 )};var vl = function(){this.h = 0 ;this.G = this.o = this.g = this.c = this.w = " ";this.m=this.b=this.C=0;Fk.M();this.a=null},wl={bh:27,btn:1,clks:2,clkt:3,pb:4,sel:5,selalt:6,tws_confirm:7,tws_lsugg:8,tws_revert:9,tws_spell:10,is:11};Ga(vl);var xl=function(){var a=DATA.DisplayLanguage,b=vl.M();b.h=2;b.w=a;return b},yl=function(a,b){" string "===typeof b&&(b=wl[b],b=null!=b?b:0);a.C=b},zl=function(a,b){if(" string "===typeof b){var c=0;0<=b.indexOf(" - k0 - ")?c = 2 :Kk(b)?c = 1 :Jk(b)&&(c = 5 );b = c}a.b = b}; dF.prototype.ub = function(a,b,c,d,e,f){var g = {cm: "g" };null! = b&& "all" ! = b&&(g.sl = b);null! = c&& "all" ! = c&&(g.tl = c);null! = d&&" "!=d&&(g.q=d);null!=e&&" "!=e&&(g.utrans=e);null!=f&&" 0 "!=f&&(g.od=f);" "!=this.a&&(g.tk=this.a,this.a=" ");eF(this," / translate_a / sg?client = webapp& "+Gj(g),a," GET ",void 0,{" cache - control ":" no - cache"})}; R(b.SHOW_MORE) + "</div><div class='tlid-show-less-link truncate-link' style='display:none'>" + R(b.SHOW_LESS) + "</div></div>" )},tK = function(a){var b = a.Qa,c = "<div class='" ;a = a.jf; for (var d = a.length,e = 0 ;e<d;e + + )c + = S(a[e]) + " " ;c + = "ttsbutton jfk-button-flat source-or-target-footer-button' aria-label='" + S(b.LISTEN) + "' data-tooltip='" + S(b.LISTEN) + "'><div class='jfk-button-img'></div></div>" ; return Q(c)},rK = function(a){var b = a.className,c = a.identifier,d = a.Si;a = a.selected;b = '<div class="' + S(b) + '-selector lang_list"><div class="lang-btn"><a class="ls-select new-ls-select ' + LK.prototype.ia = function(){var a = this.a;a.mh = 0 ;Xv(a);a = B( "text-dummy" ,this.v);var b = B( "text-dummy" ,this.v);this.a.Y().endsWith( "\n" )?E(b,this.a.Y() + "\n" ):E(b,this.a.Y());Eg(a)?(b = Kq(a),a = (a.scrollHeight - b.top - b.bottom) / 32 ):a = 1 ;V(this.gb, "small-font" ,a>OK[ "small-font" ]);Xv(this.a)};var TK = function(a){J.call(this);this.v = a;this.a = null;this.o = this.h = " ";this.g=this.c=!1};ka(TK,J);TK.prototype.w=function(a){null!=a&&null!=a.reset&&(this.c=a.reset,this.h=a.sourceLanguageCode||" ",this.o=a.targetLanguageCode||" ");this.dispatchEvent(" close_requested ")};TK.prototype.m=function(a){null!=a&&a.available&&!this.g&&(this.dispatchEvent(" tasks_available "),this.g=!0)};TK.prototype.b=function(){return!0};var UK=function(a,b,c,d,e,f){var g=ov();pF.call(this,a,c,d,e,g);this.O=f;this.w=b};ka(UK,pF);UK.prototype.m=function(){this.h.style.left=Math.round(this.coords[0])+" px ";this.h.style.bottom=Math.round(this.coords[1])+" px "};UK.prototype.g=function(){(new sF(this.w,this.O)).play()};var VK=function(){X.call(this);this.h=null};ka(VK,X);VK.prototype.b=function(){return" "};VK.prototype.setVisible=function(a,b){var c=this,d=this.j();if(Aq(d)!=a){var e=B(this.b(),this.j());a?(eq(d,{opacity:1}),eq(e,{opacity:0}),W(d,!0),(new UK(d,e,WK,XK,225,100)).play(),b&&(this.h=window.setTimeout(function(){return c.setVisible(!1)},b))):((new tF(d,195)).play(),this.h&&(window.clearTimeout(this.h),this.h=null))}};var WK=[0,-48],XK=[0,0];var YK=function(){VK.call(this)};ka(YK,VK);YK.prototype.b=function(){return" ntfcn - ctr "};YK.prototype.Xc=function(a){if(!a||" DIV "!=a.tagName)return!1;a=B(" ntfcn - ctr ",a);return a&&" DIV "==a.tagName?(a=B(" snck - msg ",a))&&" SPAN "==a.tagName?!0:!1:!1};YK.prototype.aa=function(){};var ZK=function(){};ka(ZK,zr);ZK.prototype.Zc=function(a){return a&&" SPAN "==a.tagName?!0:!1};var $K=function(a,b,c,d){VK.call(this);this.m=a;this.c=b;this.R=c;this.N=d;this.W=new yv(" ######");this.V=new ZF(DATA.Messages.CHARACTER_LIMIT);this.X=new ZF(DATA.Messages.TRANSLATE_NEXT);this.g="";this.w=null;this.C=new Im;this.C.c="webapp";this.F=K.M()};ka($K,VK);$K.prototype.b=function(){return"ovfl-ctr"};$K.prototype.Xc=function(a){return a&&"DIV"==a.tagName?(a=B(this.b(),a))&&B("snck-msg",a)&&B("ovfl-xlt",a)?!0:!1:!1}; |
非常像:
文件名translate_m_zh-CN.js
感觉或许是:对于(从英文?)翻译为中文,所以后缀是zh-CN.js ?
去看看别人如何说
google 翻译 tk参数
4年前的代码:几乎可以肯定是不能用了。google生成tk的逻辑肯定早就变了。
也是2016年,老的,肯定没用。
谷歌翻译(Google Translate) TKK值,tk值算法,api接口公布 – 『编程语言区』 – 吾爱破解 – LCG – LSG |安卓破解|病毒分析|破解软件|www.52pojie.cn
2018年的,或许可用
“2018年12月12日:最近谷歌翻译好像更新了,其实并没有,主要还是ttk位置变了下(还是原来地方),tk的算法还是可用的…”
那或许现在真的可用。
不过我是要python版本的。
或许可用?

果然不可用了。。。
转载请注明:在路上 » 【未解决】搞懂google翻译网页源码内部中生成tk参数的逻辑