分类
未分类

My hosts

http://106.13.28.197:8888/

182.61.111.162 (香港)

101.201.69.92 (ryt)

“My hosts”上的3条回复

#百度翻译

import http.client
import hashlib #md5替换
import urllib
import random
import requests
import json
import time

def creaturl(yuan=”en”,mubiao=”zh”,txt=”Acrocephalus orientalis”):#接收三个字符串参数
appid = ‘20151113000005349’
secretKey = ‘osubCEzlGjzvw8qdQc41’
httpClient = None
myurl = ‘/api/trans/vip/translate’
q = txt
fromLang = yuan
toLang = mubiao
salt = random.randint(32768, 65536)
sign = appid+q+str(salt)+secretKey
#对签名进行加密
m2=hashlib.md5(sign.encode(encoding=’UTF-8′)).hexdigest()
myurl = myurl+’?appid=’+appid+’&q=’+urllib.parse.quote(q)+’&from=’+fromLang+’&to=’+toLang+’&salt=’+str(salt)+’&sign=’+m2
return myurl
def requ(myurl):
try:
re=requests.get(“https://fanyi-api.baidu.com”+myurl)
dic=json.loads(re.text)
src = dic[“trans_result”]
print(src)#取得翻译后的文本结果,测试可删除注释
for word in src:
print(word[“src”]+’|’+word[“dst”])
with open(“words999.txt”,”a+”) as fout:
fout.write(word[“src”]+’|’+word[“dst”]+”\n”)

except Exception as e:
pass

def main():
with open(“words1.txt”,”r”) as f:
links=f.readlines()
i=0
words=””
for j in links:
i+=1
words+=j
if i%3==0:
#print(words)
content=creaturl(txt=words)
requ(content)
words=””
time.sleep(1.01)
if __name__ == ‘__main__’:
main()

发表评论

电子邮件地址不会被公开。 必填项已用*标注