"""Inspect the HTML structure to find test period / sections.""" from pathlib import Path from lxml import html for label, fn in [("IS", "IS-ReportTester-52845377.html"), ("OOS", "OOS-ReportTester-52845377.html")]: p = Path("reports") / fn raw = p.read_bytes() text = raw.decode("utf-16") if raw[:2] in (b"\xff\xfe", b"\xfe\xff") else raw.decode("utf-8", errors="replace") tree = html.fromstring(text) print(f"=== {label} ({fn}) ===") # Find the test period row for row in tree.iter("tr"): cells = row.findall("td") or row.findall("th") if len(cells) < 2: continue label_t = cells[0].text_content().strip() if any(k in label_t for k in ["期间", "Period", "建模", "Model", "前向", "Forward", "起止", "Date"]): value = cells[1].text_content().strip() print(f" {label_t}: {value}") # Look for big section headers print(f" -- h1/h2/h3 headers --") for tag in ("h1", "h2", "h3", "h4"): for el in tree.iter(tag): t = (el.text_content() or "").strip() if t: print(f" <{tag}>: {t}") # Count tables and tr tables = tree.findall(".//table") print(f" tables: {len(tables)}") total_tr = sum(len(t.findall(".//tr")) for t in tables) print(f" total