import re
import time
file1 = open(r'..\data\朗文双解清洗'+str(time.time())+'.csv', 'a',encoding='utf-8')
with open(r'..\data\朗文双解.csv',encoding='utf-8') as file:
    conten = file.readlines()
    for lin in conten:
        word=re.findall(r'^.*\t', lin)
        en = re.findall(r'<font class=L_SYL>(.*?)</span>', lin)
        str_first1 = re.sub('<font color=black>',"|",str(en))
        str_first2 = re.sub('<span class=L_POS>',"|",str(str_first1))
        str_first3 = re.sub('</font>',"|",str(str_first2))
        str_first4 = re.sub('<.*?>',"",str(str_first3))
        # print(str_first2)
        gg = str(word)+'\t'+str_first4 +'\n'
        file1.write(gg)
        print(word,str_first4)

标签: 朗文词典, python清洗

添加新评论