中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

python寫的翻譯腳本

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
    # -*- coding:utf-8 -*-    
    #!/usr/bin/env  python  
      
    import  re  
    import  urllib  
    import  urllib2  
    import  sys  
      
    class dict :  
        def __init__(self):  
            reload(sys)  
            sys.setdefaultencoding('utf8')    
        def serach(self):  
            waitWord = raw_input("輸入要查詢的內容:")  
            waitWord = urllib.quote(waitWord)  
      
            baiduUrl = "http://dict.youdao.com/search?q="+waitWord+"&keyfrom=dict.index"  
      
            userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:32.0) Gecko/20100101 Firefox/32.0'  
            headers = {'User-Agent':userAgent}  
            req = urllib2.Request(baiduUrl,headers = headers)  
            Res = urllib2.urlopen(req)  
            ResultPage = Res.read().decode("utf-8")  
      
            show = re.findall(r'<div class="trans-container">.*<div id="webTrans" class="trans-wrapper trans-tab">',ResultPage,re.S)  
            try:  
                s = show[0].decode("utf-8")  
                pos = re.findall(r'<li>.*<\/li>',s,re.S)  
                arr = pos[0].split('\n')  
                if len(arr)>0:  
                    for x in arr:  
                        print re.sub('<[^>]+>','',x).strip()  
            except :  
                print '沒有查到'  
      
      
    if __name__ == '__main__':  
        mydict  = dict()  
        mydict.serach()  

標簽: linux

版權申明:本站文章部分自網絡,如有侵權,請聯系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯系。

上一篇:三種Python下載url并保存文件的代碼

下一篇:python計算GPS兩點之間的中間點