1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| import re import time import execjs import requests
cookies = { 'BAIDUID': 'F939638C0836A775A551394EA49AC126:SL=0:NR=10:FG=1', 'ZFY': 'vJGxZYlEfVpvkXfXJnQ5YjtydbbSk:B3sBx6xbTr2dqg:C', 'BAIDUID_BFESS': 'F939638C0836A775A551394EA49AC126:SL=0:NR=10:FG=1', 'PSTM': '1700663540', 'BIDUPSID': 'F939638C0836A775F2431FDE836896A0', 'H_PS_PSSID': '39676_39713_39780_39790_39703_39796_39684_39662_39679_39817_39783_39841', '__bid_n': '18a98c645269552d29cf9b', 'BDUSS': '3drSTQ4V3VCU2xGaDJrakhHZU5MWXVIbHRtTWtVY3pRTmhueFNIR2piU2VnZmxsRVFBQUFBJCQAAAAAAAAAAAEAAAA9aUaiYmFpZHVfdWlkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ700WWe9NFla', 'BDUSS_BFESS': '3drSTQ4V3VCU2xGaDJrakhHZU5MWXVIbHRtTWtVY3pRTmhueFNIR2piU2VnZmxsRVFBQUFBJCQAAAAAAAAAAAEAAAA9aUaiYmFpZHVfdWlkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ700WWe9NFla', 'smallFlowVersion': 'old', 'RT': '"z=1&dm=baidu.com&si=42va2gpjvkg&ss=lu2lybge&sl=3&tt=2pp&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=2nvg&ul=2onn&hd=2pxh"', 'Hm_lvt_64ecd82404c51e03dc91cb9e8c025574': '1711108849', 'APPGUIDE_10_7_2': '1', 'REALTIME_TRANS_SWITCH': '1', 'FANYI_WORD_SWITCH': '1', 'HISTORY_SWITCH': '1', 'SOUND_SPD_SWITCH': '1', 'SOUND_PREFER_SWITCH': '1', 'Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574': '1711114617', 'ab_sr': '1.0.1_ZGE0NjI0MGE5YWQxMjhiZWY4MGE0NDA4Yzk3M2M5MDAwZTc0N2U1ZmU4ZDAzNGJjNDVkMWVhYmExOGJkMDM1OTkzM2I5ZDEzMjQyMWU1NjY3MGFjNjQwYWI2ZjU2Mzc0NDZjYWNkZjhlNTI4NGYzYjYxMmQ0ZGRlMmI0ODEzMDVkYjQ2ZWU4NzZiYWE1ZDNhNGI3NzRlOTIwZGVhNTYyMjU4ZGQzNmVmZDZlOWEyMWI4MmIxMTkwZDkyNWU4ZmIw', }
headers = { 'Accept': '*/*', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Acs-Token': '1711108805423_1711114643856_U/P1qQ7qhwJbUjFlDdaZOJII7xNDaZbtFXRzes9bvQe0EJVjAHtnb8hgRVtGuPrBvfR0KN+jQYxYG9gcYDYiLTaI82AZRJErUaZiVjnPlgXOP7SSpzVTb6/Jr03V0IUEq2svRifdTPhVsmfYSrQCl7yOV6OLJQHB1O6bjVLcHLoY5FVx5+mpiPuFrVMBEOGrA1lsZ0vgbXsMKn8eGjF040xYWQWxGv2jCH4/gJDUghkq1lGa5aQSdDgJo4oYQWOkMrP99HhUyfp6XO2Xl87tBXS0L1d8CuUpe/yX4cgq1oP2olu+rz24UDYNBTnTFnMc14LxagzSgfbJvlVrjSs9VCg/8XvVR7uDf8b5IOUaxaysOpZc+rR+rpBEeW5m0BuzTRhV41VSo8oNZtLyUt6cwuUKWn3NM+m4eilhnH/Qc6qqPp1yd2aRsMOM80EgneaAjoK7SGWxk3QaqkSpdk8o4WmZG4c+UNmD/49fS63TV9BRkGICDxN/nB5oUQ1RUwWl', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Origin': 'https://fanyi.baidu.com', 'Referer': 'https://fanyi.baidu.com/', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-origin', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0', 'X-Requested-With': 'XMLHttpRequest', 'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', }
params = { 'from': 'zh', 'to': 'en', }
word = input(str("请输入中文:")) session_ = requests.session()
res1 = session_.get('https://fanyi.baidu.com/', headers=headers)
res2 = session_.get('https://fanyi.baidu.com/', headers=headers) gtk = re.search(r"gtk = \"(.*?)\";", res1.text).group(1) token = re.search(r"token: '(.*?)'", res2.text).group(1) ts = str(int(time.time()*1000)) with open("sign.js", 'r', encoding="utf-8") as f: js = f.read() js_r = execjs.compile(js) f.close() sign = js_r.call("GetSign", word, gtk) data = { 'from': 'zh', 'to': 'en', 'query': word, 'simple_means_flag': '3', 'sign': sign, 'token': token, 'domain': 'common', 'ts': ts, }
response = session_.post('https://fanyi.baidu.com/v2transapi', params=params, cookies=cookies, headers=headers, data=data) print(response.json()['trans_result']['data'][0]['dst'])
|