【笔记整理】[案例]爱词霸翻译post请求

发布时间 2023-07-17 11:15:50作者: 蕝戀
import json

if __name__ == '__main__':
    import requests

    resp = requests.post(
        url="http://ifanyi.iciba.com/index.php?c=trans&m=fy&client=6&auth_user=key_web_fanyi&sign=3b48dbb7ba810dd9",
        data={
            'from': 'zh',  # 表示被翻译的语言是自动识别
            'to': 'en',  # 表示翻译后的语言是自动识别
            'q': '牛逼'  # 要翻译的中文字符串
        }, headers={
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0",
            "referer": "http://www.iciba.com"
        })

    json_dict: dict = json.loads(resp.content)
    print(json_dict["content"]["out"])