text:文本限制5000字符。
def translate(self, text):
"""翻译"""
headers = {'X-Forwarded-For': '', 'User-Agent': (UserAgent()).random}
data = {"f": "auto", "t": "auto", "w": text}
url = "http://fy.iciba.com/ajax.php?a=fy"
response = s.post(url, headers=headers, data=data, timeout=15).text
obj = json.loads(response)
time.sleep(1)
status = obj.get('status')
content = obj.get('content')
if status == 1:
out = content.get('out')
return out
else:
word_mean, out = "".join(content.get("word_mean")), ''
mean = re.findall(r";(.*?);", word_mean)
if not mean:
mean = re.findall(r"(.*?);", word_mean)
if mean:
out = mean[0]
return out
网友评论