用Python实现一个“百度翻译”

import requests
import json


s = input("请输入你要翻译的内容:")
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"}
post_data = {
    "fromLang": "auto-detect",
    "text": s,
    "to": "en"
    }

post_url = "https://cn.bing.com/ttranslatev3?isVertical=1&&IG=69AE79EB80F34E39A33C0574E30DF1FE&IID=translator.5025.1"

res = requests.post(post_url, headers=headers, data=post_data)
string = res.content.decode()
print("翻译结果:", json.loads(string)[0]["translations"][0]["text"])
输入你要翻译的内容:人生苦短,我用Python
翻译结果: Life is short, I use Python

原文地址:https://www.cnblogs.com/waterr/p/13894270.html