zoukankan      html  css  js  c++  java
  • 有道

    import urllib.request
    import urllib.parse
    import json
    import time
    while True:
        content = input('请输入需要翻译的内容:(输入"q!"退出程序):')
        if content == 'q!':
            break
        url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=http://www.youdao.com/'
        #head 里面的内容
        data = {}
        data['type'] = 'AUTO'
        data['i'] =  content
        data['doctype'] = 'json'
        data['xmlVersion'] = '1.8'
        data['keyfrom'] = 'fanyi.web'
        data['ue'] = 'UTF-8'
        data['action'] = 'FY_BY_CLICKBUTTON'
        data['typoResult'] = 'true'
        data = urllib.parse.urlencode(data).encode('UTF-8')  #将content 转换为utf-8形式传给服务器
        req = urllib.request.Request(url,data)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36') #模拟浏览器进行访问
        response = urllib.request.urlopen(req)
        html = response.read().decode('UTF-8') #将内容从utf-8转换过来
        target = json.loads(html)
        type(target)
        print ("翻译结果:%s"%(target['translateResult'][0][0]['tgt']))
        time.sleep(5) #每一次进行5秒钟的停顿
  • 相关阅读:
    NetworkInterface网速监测
    动态编译
    JSON C# Class Generator
    Cookie中的HttpOnly
    webapi session
    没有为扩展名“.html”注册的生成提供程序
    转 C# 使用openssl
    openssl jia adress
    扩展JS
    bootstrap 模态
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4677725.html
Copyright © 2011-2022 走看看