import re
text = ""
with open("read.html", "r") as rf:
text = rf.read()
pattern = r"<link[\s\S]*?<link"
results = re.findall(pattern, text)
if results:
r = results[0]
with open("write.html", "w") as wf:
wf.write(r)
================================================
with open("read.html", "r") as rf:
with open("write.html", "w") as wf:
num = 0
for line in rf.readlines():
if line.startswith("<link"):
num += 1
continue
if num == 2:
break
wf.writelines(line)
人生最曼妙的风景,竟是内心的淡定与从容!