19 lines
772 B
Python
19 lines
772 B
Python
#!/usr/bin/env python
|
|||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""一次性探针跑手:把某个 html 丢给无头 Chrome,取回 #out 的文本。"""
|
||
|
|
import subprocess, re, html, os, sys
|
||
|
|
|
||
|
|
CHROME = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
|
||
|
|
target = sys.argv[1]
|
||
|
|
hashpart = sys.argv[2] if len(sys.argv) > 2 else ""
|
||
|
|
abs_p = os.path.abspath(target).replace("\\", "/")
|
||
|
|
url = "file:///" + abs_p + hashpart
|
||
|
|
cmd = [CHROME, "--headless=new", "--no-sandbox", "--disable-gpu",
|
||
|
|
"--virtual-time-budget=5000", "--dump-dom", url]
|
||
|
|
r = subprocess.run(cmd, capture_output=True)
|
||
|
|
s = r.stdout.decode("utf-8", "replace")
|
||
|
|
m = re.search(r'<div id="out">(.*?)</div>', s, re.S)
|
||
|
|
if m:
|
||
|
|
print(html.unescape(re.sub(r"<[^>]+>", "", m.group(1))))
|
||
|
|
else:
|
||
|
|
print("NOMATCH len=%d" % len(s))
|