首页 > 其他分享 >02. 百度翻译

02. 百度翻译

时间:2022-11-19 23:57:09浏览次数:70  
标签:02 翻译 String 百度 && var data concat fromCharCode

百度翻译

import requests
import os
import jmespath


class Baidu:
    headers = {
        "Cookie": "APPGUIDE_10_0_2=1; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; BAIDUID=3103D5F748443ACB7699ABBFC3CDE425:FG=1; BIDUPSID=3103D5F748443ACB7699ABBFC3CDE425; PSTM=1664807775; BAIDUID_BFESS=3103D5F748443ACB7699ABBFC3CDE425:FG=1; newlogin=1; Hm_lvt_246a5e7d3670cfba258184e42d902b31=1667137554; __bid_n=1843398a98284eda384207; BDUSS_BFESS=pSYWxFOWpvU0pTU3B4d09WejlUZHB-ZzNIaE1Ga3g5dnA3N2VWbWNRRmg5SkZqRUFBQUFBJCQAAAAAAAAAAAEAAAD3riNIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGFnamNhZ2pjSE; ZFY=eudKoYio2SIwEtUhHuw1m7jrTxaHXaUC5NI5giZveQk:C; MCITY=-75%3A; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1667137537,1667560091,1668257199,1668864308; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1668870595; ab_sr=1.0.1_ZDM5MzIwYTJiMzRmMzc5ZWQ0NDc5ZDE5MDkwZDYzYjNmY2UxMTg0OGMxMTQ0MTU2MjQzMzNkZmI4ZDYyNWVmZmY4OGFjNWZiZmI0YjQyZjk5ZWQyNjVhYjRiYTM0ZmE3ZWRiMjdmOWMxZDRmODQxYjllZWQzNzJlYzdiMWMzYjhlNjVhM2Y0ODZiM2RjY2ZmNjkzOTJiYjYwZjk0N2YxOTE4ZjM3MGZjOTljNWEzZjdlMTFiNWY3YTlhOWI3YzIx",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42",
    }

    def http(self, data, sign):
        url = "https://fanyi.baidu.com/v2transapi?from=zh&to=en"

        data = {
            "from": "zh",
            "to": "en",
            "query": data,
            "transtype": "translang",
            "simple_means_flag": "3",
            "sign": sign,
            "token": "6b35d34118d4557ba80818ef1550e90b",
            "domain": "common"
        }
        response = requests.post(url, headers=self.headers, data=data)
        return response.json()

    # 访问js文件,获取结果
    def decrypto_sign(self, data: str):  # 加密字符串
        po = os.popen(r"node D:\nodepro\project\11.js {}".format(data))  # <推荐>
        m = po.buffer.read().decode('utf-8').strip()
        return m

    def run(self):
        data = '我喜欢你'
        sign = self.decrypto_sign(data)
        result = self.http(data, sign)
        print(f'{data}-----------------', jmespath.search('trans_result.data[0].dst', result))


if __name__ == '__main__':
    s = Baidu()
    s.run()

 

var window = {};
function n(t, e) {
    for (var n = 0; n < e.length - 2; n += 3) {
        var r = e.charAt(n + 2);
        r = "a" <= r ? r.charCodeAt(0) - 87 : Number(r),
            r = "+" === e.charAt(n + 1) ? t >>> r : t << r,
            t = "+" === e.charAt(n) ? t + r & 4294967295 : t ^ r
    }
    return t
}
var r = "320305.131321201"; // js代码下是null, 该值来源于页面源代码下  window.gtk = "320305.131321201";

function  aaa(t) {
    var o, i = t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g);
    if (null === i) {
        var a = t.length;
        a > 30 && (t = "".concat(t.substr(0, 10)).concat(t.substr(Math.floor(a / 2) - 5, 10)).concat(t.substr(-10, 10)))
    } else {
        for (var s = t.split(/[\uD800-\uDBFF][\uDC00-\uDFFF]/), c = 0, u = s.length, l = []; c < u; c++)
            "" !== s[c] && l.push.apply(l, function(t) {
                if (Array.isArray(t))
                    return e(t)
            }(o = s[c].split("")) || function(t) {
                if ("undefined" != typeof Symbol && null != t[Symbol.iterator] || null != t["@@iterator"])
                    return Array.from(t)
            }(o) || function(t, n) {
                if (t) {
                    if ("string" == typeof t)
                        return e(t, n);
                    var r = Object.prototype.toString.call(t).slice(8, -1);
                    return "Object" === r && t.constructor && (r = t.constructor.name),
                        "Map" === r || "Set" === r ? Array.from(t) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? e(t, n) : void 0
                }
            }(o) || function() {
                throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
            }()),
            c !== u - 1 && l.push(i[c]);
        var p = l.length;
        p > 30 && (t = l.slice(0, 10).join("") + l.slice(Math.floor(p / 2) - 5, Math.floor(p / 2) + 5).join("") + l.slice(-10).join(""))
    }
    for (var d = "".concat(String.fromCharCode(103)).concat(String.fromCharCode(116)).concat(String.fromCharCode(107)), h = (null !== r ? r : (r = window[d] || "") || "").split("."), f = Number(h[0]) || 0, m = Number(h[1]) || 0, g = [], y = 0, v = 0; v < t.length; v++) {
        var _ = t.charCodeAt(v);
        _ < 128 ? g[y++] = _ : (_ < 2048 ? g[y++] = _ >> 6 | 192 : (55296 == (64512 & _) && v + 1 < t.length && 56320 == (64512 & t.charCodeAt(v + 1)) ? (_ = 65536 + ((1023 & _) << 10) + (1023 & t.charCodeAt(++v)),
            g[y++] = _ >> 18 | 240,
            g[y++] = _ >> 12 & 63 | 128) : g[y++] = _ >> 12 | 224,
            g[y++] = _ >> 6 & 63 | 128),
            g[y++] = 63 & _ | 128)
    }
    for (var b = f, w = "".concat(String.fromCharCode(43)).concat(String.fromCharCode(45)).concat(String.fromCharCode(97)) + "".concat(String.fromCharCode(94)).concat(String.fromCharCode(43)).concat(String.fromCharCode(54)), k = "".concat(String.fromCharCode(43)).concat(String.fromCharCode(45)).concat(String.fromCharCode(51)) + "".concat(String.fromCharCode(94)).concat(String.fromCharCode(43)).concat(String.fromCharCode(98)) + "".concat(String.fromCharCode(43)).concat(String.fromCharCode(45)).concat(String.fromCharCode(102)), x = 0; x < g.length; x++)
        b = n(b += g[x], w);
    return b = n(b, k),
    (b ^= m) < 0 && (b = 2147483648 + (2147483647 & b)),
        "".concat((b %= 1e6).toString(), ".").concat(b ^ f)
}


// # js文件下(弊端:会造成一些符号的缺失)
argv = process.argv[2] // python文件传递的data
// console.log(argv)
console.log(aaa(argv))

 

标签:02,翻译,String,百度,&&,var,data,concat,fromCharCode
From: https://www.cnblogs.com/modly/p/16907561.html

相关文章

  • 2022-11-19学习内容-Server端代码编写-Client端代码编写
    1.Server端代码编写1.1UserDBHelper.javapackagecom.example.chapter07_server.database;importandroid.content.Context;importandroid.database.sqlite.SQLiteD......
  • 2022.47 AI中的算法与模型
    最近工作中,发现不少人对AI中的算法和模型的概念分不清楚,导致思考沟通表达问题不准确,其实这两个概念还是有很大差别的。AI中的算法,是指在已知样本数据基础上,按照预先设定的......
  • 代码随想录算法训练营Day04|24. 两两交换链表中的节点、19. 删除链表的倒数第 N 个结
    代码随想录算法训练营Day04|24.两两交换链表中的节点、19.删除链表的倒数第N个结点、02.07.链表相交、142.环形链表II24.两两交换链表中的节点题目链接:24.两两交......
  • 2022.11.19
    ###noip模拟又炸了。。。。。。##出错点t1:又假了,问题是自己知道假了还没想着写暴力##过程分析半小时通读完先开得t2,因为有个点没转化过来,打了个多一个二分log的......
  • 散乱的思绪-2022.11.19
    我是一个什么都想要,梦想着一步登天的妄想者。我没有一颗聪明绝顶的脑袋,也没有出众样貌,更没有父母的日复一日劳作的毅力。有时候我在想,我是一个什么样的人呢?在我看来我大概......
  • 02 创建型模式-工厂方法模式
    一、工厂方法模式抽象产品:描述具体产品的公共接口。具体产品:象产品的子类,工厂类要创建的目标类,描述生产的具体产品。抽象工厂:描述具体工厂的公共接口。具体工厂:抽象工......
  • #yyds干货盘点#【愚公系列】2022年11月 微信小程序-多人音视频对话
    前言微信小程序开发多人音视频对话首先得去小程序管理后台,「开发」-「接口设置」中自助开通该组件权限。相关属性:一级类目/主体类型二级类目小程序内容场景教......
  • CSP-J 2022游记
    本文章同步发布于洛谷博客初赛初赛-90天从今年暑假开始学习。教练说我很有天赋,所以暑假直接跟着入门班上。整个暑假就是在持续学基础知识,最后几周开始刷前几年的复......
  • 024.PageHelper分页插件
    1.分页查询要面临的问题  2.使用流程  2.1pom.xml<dependency><groupId>com.github.pagehelper</groupId><artifactId>pag......
  • 华东交通大学2022双基ACM竞赛
    比赛链接:https://ac.nowcoder.com/acm/contest/44482签到:AEI碎碎念:好家伙,题目里全是心怡。A:心怡的魔法城堡原题链接:心怡的魔法城堡题意:闯入者可以选择到达上出口或......