python 百度翻译 api 调用 (官方文档改编)

代码由官方文档改编而来  是python3版本

官方链接

做完后,发现,这就是个爬虫啊,还是官方主动喂食的

# -*- coding: utf-8 -*-

# This code shows an example of text translation from English to Simplified-Chinese.
#此代码显示了从英语到简体中文的文本翻译示例。

# This code runs on Python 2.7.x and Python 3.x.
# 此代码能在 ... 和 ... 上运行
# You may install `requests` to run this code: pip install requests
#你需要  requests  库 运行代码 , 使用  pip install requests 安装
# Please refer to `https://api.fanyi.baidu.com/doc/21` for complete api document
# 详细信息请查看 官方文档

import requests
import random
import json
from hashlib import md5

# Generate salt and sign
def make_md5(s, encoding='utf-8'):
    return md5(s.encode(encoding)).hexdigest()


# text 是将要翻译的文本
def get_it(text):
    # Set your own appid/appkey.  设置您自己的appid/appkey。
    appid = '自行申请'
    appkey = '自行申请'

    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

将来怎么办

你的鼓励是我的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值