标签:lines readline 域名 findall com main python pre close
import re DOMAIN =[] f = open(‘test.txt‘,‘r‘,encoding=‘UTF-8‘) w = open(‘domain.txt‘,‘w‘) for data in f.readlines(): domain = re.findall(r"\w+\.+baidu.com", data) for i in domain: if i not in DOMAIN: DOMAIN.append(i) domain = re.findall(r"\w+\.+\w+\.+baidu.com", data) for i in domain: if i not in DOMAIN: DOMAIN.append(i) domain = re.findall(r"\w+\.+\w+\.+\w+\.+baidu.com", data) for i in domain: if i not in DOMAIN: DOMAIN.append(i) for i in DOMAIN: w.write(str(i)+‘\n‘) w.close()
丑是丑了点,懒得改了
标签:lines readline 域名 findall com main python pre close
原文地址:https://www.cnblogs.com/zuoxiaolongzzz/p/12494428.html