python翻译软件实现代码(使用google api完成)
时间:2023-05-19 17:25:43
# -*- coding: utf-8 -*-
import httplib
from urllib import urlencode
import re
def out(text):
p = re.compile(r'","')
m = p.split(text)
print m[0][4:].decode('UTF-8').encode('GBK')
if __name__=='__main__':
while True:
word=raw_input('Input the word you want to search:')
text=urlencode({'text':word})
h=httplib.HTTP('translate.google.cn')
h.putrequest('GET', '/translate_a/t?client=t&hl=zh-CN&sl=en&tl=zh-CN&ie=UTF-8&oe=UTF-8&'+text)
h.endheaders()
h.getreply()
f = h.getfile()
lines = f.readlines()
out(lines[0])
f.close()
haskell版
module Main where
import Network.HTTP
import Text.Regex.Posix
main = do
putStrLn "Input the word you want to search:"
word <- getLine
handle <- simpleHTTP (getRequest $ "http://translate.google.cn/translate_a/t?client=t&hl=zh-CN&sl=en&tl=zh-CN&ie=UTF-8&oe=UTF-8&" ++ (text word))
content <- getResponseBody handle
let match = (content =~ "\",\""::(String,String,String))
putStrLn $ drop 4 $ first match
main
text word = urlEncodeVars [("text",word)]
first::(String,String,String)->String
first (x,_,_) = x
作者:Hevienz
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
利用python爬取软考试题之ip自动代理
![](https://img.aspxhome.com/file/2023/4/127024_0s.png)
对python的bytes类型数据split分割切片方法
python使用cookielib库示例分享
MYSQL安装时解决要输入current root password的解决方法
asp javascript值的互相传递方法
BERT vs GPT自然语言处理中的关键差异详解
举例讲解Python程序与系统shell交互的方式
golang 实现时间滑动窗口的示例代码
![](https://img.aspxhome.com/file/2023/4/109234_0s.png)
MySQL并发更新数据时的处理方法
![](https://img.aspxhome.com/file/2023/9/71049_0s.jpg)
详细解读Python中的json操作
![](https://img.aspxhome.com/file/2023/3/81593_0s.png)
在Python中使用HTML模版的教程
![](https://img.aspxhome.com/file/2023/1/103111_0s.png)
vue项目持久化存储数据的实现代码
MySQL root账号远程新建数据库报错1044问题及解决方法
![](https://img.aspxhome.com/file/2023/0/105680_0s.png)
Python实现读取csv文件并进行排序
在Python运行时动态查看进程内部信息的方法
解决python-redis-lock分布式锁的问题
![](https://img.aspxhome.com/file/2023/3/98783_0s.png)
Python定义函数实现累计求和操作
![](https://img.aspxhome.com/file/2023/7/66457_0s.jpg)
Python3 venv搭建轻量级虚拟环境的步骤(图文)
![](https://img.aspxhome.com/file/2023/5/68385_0s.jpg)
opencv3/python 鼠标响应操作详解
![](https://img.aspxhome.com/file/2023/8/101588_0s.jpg)
list视图方式设计浅析
![](https://img.aspxhome.com/file/UploadPic/200812/21/01-28s.jpg)