# -*- coding: utf-8 -*-
import html as H

p = r"D:\workbbbbbb\build\_dom.html"
raw = open(p, "rb").read()
s = None
for enc in ("utf-8", "gbk", "utf-16"):
    try:
        s = raw.decode(enc)
        break
    except Exception:
        continue
if s is None:
    s = raw.decode("utf-8", errors="replace")


def grab(node_id, sep):
    i = s.find('id="%s"' % node_id)
    if i < 0:
        return "[%s NOT FOUND]" % node_id
    j = s.find(">", i)
    k = s.find("</div>", j)
    return H.unescape(s[j + 1:k]).replace(sep, "\n")


out = "===== E2E =====\n" + grab("E2E", "  ||  ") + "\n\n===== E2E2 =====\n" + grab("E2E2", "  ||  ")
out += "\n\ndomLen=%d" % len(s)
open(r"D:\workbbbbbb\build\_e2e_out.txt", "w", encoding="utf-8").write(out)
print("wrote %d chars" % len(out))
