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