f = open('ren.txt', 'r',encoding='UTF-8') x=[] for line in f: x.append(line) f.close() z=[] for x1 in x: x2=x1.split("</a>") for x3 in x2: if "http" in x3: z.append(x3) c=[] for z1 in z: z2=z1.split(">") m=len(z2)-1 c.append(z2[m]) f1 = open('sc.txt', 'w',encoding='UTF-8') for c1 in c: f1.write(c1) f1.write("\n") f1.close()