目標文件夾:
文件內容:
實現代碼:html
# -*- coding:utf-8 -*- # __author__ :kusy # __content__:get ssr info from html files # __date__:2018/10/29 14:43 import os import re def getssr(): srcdir = os.path.abspath('src') files = os.listdir(srcdir) filestr = '' for file in files: with open(srcdir + '\\' + file,'r',encoding='utf-8') as f: filestr = filestr + f.read() regexp = re.compile('ssr://[A-Za-z0-9]*') mystr = regexp.findall(filestr) # 去重 mystr = list(set(mystr)) return mystr if __name__ == '__main__': with open(os.path.abspath('ssr.log'),'w') as newfile: newfile.writelines(s + '\n' for s in getssr())
提取結果:spa