代码由官方文档改编而来 是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 = '自行申请'