25469

网页简体变为繁体

''' 1.读取本地网页 2.匹配页面中的中文 3.转换为繁体'''import refrom Fan_Jian.langconv import *import Fan_Jian.zh_wikiimport multiprocessingimport osclass Fan_jian_change(object): # 读取本地所有的网页源码文件 def read_local_web(self): dir_name = '../file' name_list = os.listdir(dir_name) for name in name_list: with open(name, 'r', encoding='utf-8') as f: web_data = f.readlines() return web_data # 将读取到的web源代码进行正则匹配,匹配出所有的汉字 # 将匹配出的简体汉字转换为繁体 def re_change(self, web_data): sentence = Converter('zh-hant').convert(web_data) for i in range(2): with open('../end/{}.txt'.format(i), 'a+', encoding='utf-8') as f: f.write(sentence) print('网站转换成功..') def main(self): web_data = self.read_local_web() q = multiprocessing.Pool(10) q.apply_async(self.re_change, args=(web_data,))if __name__ == '__main__': f = Fan_jian_change() f.main()

来源:博客园

作者:Victor_JJ

链接:https://www.cnblogs.com/victorstudy/p/11425894.html

Recommend