29 lines
762 B
Python
29 lines
762 B
Python
import json, websocket, urllib.request
|
|
|
|
resp = urllib.request.urlopen("http://127.0.0.1:9222/json/list")
|
|
pages = json.loads(resp.read().decode("utf-8"))
|
|
page = next(p for p in pages if p.get("type") == "page" and "odacm.cn" in p.get("url"))
|
|
ws_url = page["webSocketDebuggerUrl"]
|
|
|
|
ws = websocket.WebSocket()
|
|
ws.connect(ws_url, timeout=5)
|
|
|
|
# 点击“关闭”系统设置弹窗
|
|
script = """
|
|
(() => {
|
|
const closeBtn = document.querySelector('.close-button');
|
|
if (closeBtn) {
|
|
closeBtn.click();
|
|
return 'Closed settings modal';
|
|
}
|
|
return 'Close button not found';
|
|
})()
|
|
"""
|
|
ws.send(json.dumps({
|
|
"id": 1,
|
|
"method": "Runtime.evaluate",
|
|
"params": {"expression": script, "returnByValue": True}
|
|
}))
|
|
print(ws.recv())
|
|
ws.close()
|