pursue wind pursue wind
首页
Java
Python
数据库
框架
Linux
中间件
前端
计算机基础
DevOps
项目
面试
书
关于
归档
MacOS🤣 (opens new window)
GitHub (opens new window)
首页
Java
Python
数据库
框架
Linux
中间件
前端
计算机基础
DevOps
项目
面试
书
关于
归档
MacOS🤣 (opens new window)
GitHub (opens new window)
  • 基于Python轻松自建App服务器

    • 0App 与后端服务器通信方法简介
    • 1本小册要完成的通信场景功能
    • 2服务器端组件框架的选择与介绍
    • 3基于腾讯云的服务器端环境搭建
    • 4基于 Tornado 的 HTTP 服务器简介及代码组织框架
    • 5第一次数据请求 1:服务器接收用户注册信息
    • 6第一次数据请求 2:为用户处理模块增加 log 管理
    • 7第一次数据请求 3:将用户信息写入 MySQL 数据库
    • 8服务器接收客户端图片上传,并保存在硬盘中
    • 9服务器接收客户端请求,并返回 H5 页面
    • 10搭建基于 Nginx 的代理服务器
    • 11基于 HTTPS 的数据加密
    • 12大型 HTTP 服务器架构演进路线及思路
    • 13总结
  • 基于Python实现微信公众号爬虫

  • Xpath
  • python3 翻译
    • install requests
    • py
  • python3循环创建数据库表
  • python实用30个小技巧
  • pywin32
  • Python
pursuewind
2020-11-22
目录

python3 翻译

# install requests

pip install requests
1

# py

import json

import requests


# 翻译函数,word 需要翻译的内容
def translate(word):
    # 有道词典 api
    url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null'
    # 传输的参数,其中 i 为需要翻译的内容
    key = {
        'type': "AUTO",
        'i': word,
        "doctype": "json",
        "version": "2.1",
        "keyfrom": "fanyi.web",
        "ue": "UTF-8",
        "action": "FY_BY_CLICKBUTTON",
        "typoResult": "true"
    }
    # key 这个字典为发送给有道词典服务器的内容
    response = requests.post(url, data=key)
    # 判断服务器是否相应成功
    if response.status_code == 200:
        # 然后相应的结果
        return response.text
    else:
        print("有道词典调用失败")
        # 相应失败就返回空
        return None


def get_reuslt(repsonse):
    # 通过 json.loads 把返回的结果加载成 json 格式
    result = json.loads(repsonse)
    print("输入的词为:%s" % result['translateResult'][0][0]['src'])
    print("翻译结果为:%s" % result['translateResult'][0][0]['tgt'])
    src_word = result['translateResult'][0][0]['src']
    eng = str(result['translateResult'][0][0]['tgt'])
    res = eng.replace(' ', '_').upper()
    print(res)
    print("{}(200005, \"{}\")".format(res, src_word))


def translation(word):
    print("本程序调用有道词典的API进行翻译,可达到以下效果:")
    print("外文-->中文")
    print("中文-->英文")
    list_trans = translate(word)
    get_reuslt(list_trans)


if __name__ == '__main__':
    translation('联盟公告过长')

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Last Updated: 2023/01/30, 11:01:00
Xpath
python3循环创建数据库表

← Xpath python3循环创建数据库表→

Theme by Vdoing | Copyright © 2019-2023 pursue-wind | 粤ICP备2022093130号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
  • 飙升榜
  • 新歌榜
  • 云音乐民谣榜
  • 美国Billboard榜
  • UK排行榜周榜
  • 网络DJ