复刻QIMEI UUID42并默认使用无头浏览器
This commit is contained in:
@@ -96,7 +96,12 @@ class Cdp:
|
||||
return r.get("result", {}).get("value")
|
||||
|
||||
|
||||
def launch(profile: Path, port: int, headless: bool = False) -> tuple[subprocess.Popen, str]:
|
||||
def launch(profile: Path, port: int, headless: bool = True) -> tuple[subprocess.Popen, str]:
|
||||
"""启动用于 CDP 抓取的 Chrome。
|
||||
|
||||
默认使用无头模式,避免登录/抓取流程弹出窗口;传入 ``headless=False``
|
||||
仍可在需要人工观察页面时启用可视化窗口。
|
||||
"""
|
||||
args = [
|
||||
str(CHROME),
|
||||
"--no-first-run", "--no-default-browser-check",
|
||||
@@ -170,9 +175,9 @@ def cookie_names_from_header(headers: dict) -> list[str]:
|
||||
return [part.strip().split("=", 1)[0] for part in raw.split(";") if part.strip()]
|
||||
|
||||
|
||||
async def capture_round(profile: Path, tag: str, port: int):
|
||||
async def capture_round(profile: Path, tag: str, port: int, *, headless: bool = True):
|
||||
"""抓取一轮:导航序列 + 全量 Cookie 快照。"""
|
||||
proc, ws_url = launch(profile, port)
|
||||
proc, ws_url = launch(profile, port, headless=headless)
|
||||
try:
|
||||
async with websockets.connect(ws_url, max_size=64 * 1024 * 1024) as raw_ws:
|
||||
cdp = Cdp(raw_ws)
|
||||
@@ -294,14 +299,14 @@ async def capture_round(profile: Path, tag: str, port: int):
|
||||
proc.kill()
|
||||
|
||||
|
||||
async def probe_anon(profile: Path, port: int):
|
||||
async def probe_anon(profile: Path, port: int, *, headless: bool = True):
|
||||
"""复用已有 profile:复放 udblgn 匿名流程,解密请求/响应体。
|
||||
|
||||
抓取会话内 anonymousLogin 与 web/middle 的 postData 与响应体,
|
||||
然后带全套 Cookie 用 requests 独立重放 anonymousLogin,检查
|
||||
服务端是否在匿名流程中下发 guid/udb_guiddata/匿名 token 等字段。
|
||||
"""
|
||||
proc, ws_url = launch(profile, port)
|
||||
proc, ws_url = launch(profile, port, headless=headless)
|
||||
try:
|
||||
async with websockets.connect(ws_url, max_size=64 * 1024 * 1024) as raw_ws:
|
||||
cdp = Cdp(raw_ws)
|
||||
@@ -562,6 +567,11 @@ def main():
|
||||
ap.add_argument("--profile", default="/tmp/huya-browser-p1")
|
||||
ap.add_argument("--port", type=int, default=9333)
|
||||
ap.add_argument("--out", default=str(OUT_DIR))
|
||||
ap.add_argument(
|
||||
"--headed",
|
||||
action="store_true",
|
||||
help="显示 Chrome 窗口(默认使用无头模式)",
|
||||
)
|
||||
args = ap.parse_args()
|
||||
OUT_DIR = Path(args.out)
|
||||
profile = Path(args.profile)
|
||||
@@ -572,7 +582,7 @@ def main():
|
||||
if args.mode == "round2" and not (profile / "Default").exists():
|
||||
print("round2 需要先运行 round1(同一 profile)")
|
||||
sys.exit(2)
|
||||
asyncio.run(capture_round(profile, args.mode, args.port))
|
||||
asyncio.run(capture_round(profile, args.mode, args.port, headless=not args.headed))
|
||||
elif args.mode == "probe":
|
||||
# 匿名流程只在"无 udb_deviceid 持久态"的全新 profile 触发;
|
||||
# probe 模式内部使用临时全新 profile,跑完自动清理。
|
||||
@@ -581,7 +591,7 @@ def main():
|
||||
|
||||
tmp = tempfile.mkdtemp(prefix="huya-probe-")
|
||||
try:
|
||||
asyncio.run(probe_anon(Path(tmp), args.port))
|
||||
asyncio.run(probe_anon(Path(tmp), args.port, headless=not args.headed))
|
||||
finally:
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
else:
|
||||
@@ -589,4 +599,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user