首页 > 编程语言 >有道词典 python

有道词典 python

时间:2023-02-10 19:11:05浏览次数:58  
标签:python 有道 chn 词典 danciben split file each find

def youdaocidian():
    danciben_path=r"C:\Users\wx\Desktop\123.txt"
    with open(danciben_path,encoding='utf-8') as f:
        file=f.read()

    each=random.choice(file.split('</item>'))
    #print(each)
    x=(each[each.find('<word>'):each.find(']]></trans')])
    cd=x.replace('<word>','').replace('<trans><![CDATA[','')
    eng=cd.split('</word>')[0]
    chn=cd.split('</word>')[1].strip()
    return eng +'\n'+chn

 

标签:python,有道,chn,词典,danciben,split,file,each,find
From: https://www.cnblogs.com/wingxyz/p/17110082.html

相关文章