源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

python翻译软件实现代码(使用google api完成)

  • 时间:2020-02-01 16:54 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python翻译软件实现代码(使用google api完成)
[u]复制代码[/u] 代码如下:
# -*- 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版  
[u]复制代码[/u] 代码如下:
 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
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部