我写了一些代码来解析页面的HTML,并用链接替换某些单词。该脚本是从import csv
name1 = input("Enter Name:")
was_found = False
filePath = "data.csv"
with open(filePath) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if name1 == row['name']:
print("true")
was_found = True
break
if not was_found:
# looked at every row and did not find search term
print("No record found")
标记之前调用的。
问题在于放置在</head>
中嵌入脚本的页面中。当此脚本替换<body>
HTML时,这些脚本将再次执行,并且在某些情况下可能会发生疯狂的事情(例如循环)。
如何调整我的代码,以便在打印并执行body
之前完成所有替换工作?
<body>