有道词典 python

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

 

posted @ 2023-02-10 19:04  uuxyz  阅读(66)  评论(0)    收藏  举报
联系我