37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import sys
|
|
|
|
file_path = "/home/x79/sisvietnamvn_01/sisvietnamvn_Trang chính thức hiện tại/UMass Amherst _ UMass Amherst.html"
|
|
|
|
with open(file_path, "r", encoding="utf-8") as f:
|
|
lines = f.readlines()
|
|
|
|
start_idx = -1
|
|
for i, line in enumerate(lines):
|
|
if '<div class="content-top">' in line:
|
|
start_idx = i
|
|
break
|
|
|
|
if start_idx == -1:
|
|
print("Could not find <div class=\"content-top\">")
|
|
sys.exit(1)
|
|
|
|
extracted = []
|
|
div_count = 0
|
|
found_start = False
|
|
|
|
for line in lines[start_idx:]:
|
|
# Simple tag counting to find the matching closing div
|
|
# Note: this is a naive counter, it doesn't account for HTML comments or script tags containing strings that look like tags,
|
|
# but it usually works well for standard HTML layout sections.
|
|
div_count += line.count("<div")
|
|
div_count -= line.count("</div")
|
|
|
|
extracted.append(line)
|
|
if div_count == 0:
|
|
break
|
|
|
|
output_path = "src/main/resources/templates/themes/umass/content-top.html"
|
|
with open(output_path, "w", encoding="utf-8") as f:
|
|
f.writelines(extracted)
|
|
print(f"Extracted to {output_path}")
|