# coding=UTF-8 # !/usr/bin/python # encoding: utf-8 # filename: youdao-translate.py # author: gaohaixiang # writetime:202211161425 import requests import urllib.request import urllib.parse import json import time import random import hashlib def translateLines(translate): url_1 = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule' lts = str(int(time.time()*1000)) salt = lts + str(int(random.random()*10)) print(lts,salt) md5 = hashlib.md5() md5.update(("fanyideskweb" + "%s" % translate + salt + "Ygy_4c=r#e#4EX^NUGUc5").encode('utf8')) sign = md5.hexdigest() print(sign) data = {'i': "%s" % translate, 'from': 'AUTO', 'to': 'AUTO', 'smartresult': 'dict', 'client': 'fanyideskweb', 'lts': lts, 'salt': salt, 'sign': sign, 'bv': '9edd1e630b7d8f13679a536d504f3d9f', 'doctype': 'json', 'version': '2.1', 'keyfrom': 'fanyi.web', 'action': 'FY_BY_CLICKBUTTION', } cookies = {'OUTFOX_SEARCH_USER_ID': '693376202@10.108.162.139', 'OUTFOX_SEARCH_USER_ID_NCOO': '1437859245.2473195', '___rl__test__cookies': str(int(lts)-7),'UM_distinctid':'184766eebd912ba-02dbf9c5c20442-26021e51-1704a0-184766eebdab0a'} header = { 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Connection': 'keep-alive', 'Content-Length': '549', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Host': 'fanyi.youdao.com', 'Origin': 'https://fanyi.youdao.com', 'Referer': 'https://fanyi.youdao.com/', 'sec-ch-ua': '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', '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/107.0.0.0 Safari/537.36', 'X-Requested-With': 'XMLHttpRequest' } res_1 = requests.post(url_1,data=(data),headers=header, cookies=cookies) print(res_1.text) # data = urllib.parse.urlencode(data).encode('utf-8') # request = urllib.request.Request(url=url_1,headers=header, data=data,method='POST') # response = urllib.request.urlopen(request) # print(response.read().decode('utf-8')) # js = json.loads(response.read().decode('utf-8')) # print(js) if __name__ == '__main__': line = "Prometheus, a Cloud Native Computing Foundation project, is a systems and service monitoring system It collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts when specified conditions are observed." translateLines(line) # file = open("a.txt","r") # filelines = file.readlines() # file.close() # for lines in filelines: # time.sleep(0.5) # translateLines(lines)
01-15
1001
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-01
1641
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-16