42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
import sys
|
|
import time
|
|
from pathlib import Path
|
|
import json
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
from login import get_page
|
|
|
|
page = get_page(port=9222)
|
|
target_tab = page.get_tab(page.latest_tab)
|
|
|
|
target_tab.listen.start()
|
|
|
|
btn = target_tab.ele('#onSearch') or target_tab.ele('text=查询')
|
|
if btn:
|
|
btn.run_js('this.click()')
|
|
print("Clicked")
|
|
|
|
time.sleep(5)
|
|
for p in target_tab.listen.steps():
|
|
if p.method == 'POST':
|
|
print("API:", p.url)
|
|
body = p.response.body
|
|
try:
|
|
data = body if isinstance(body, (dict, list)) else json.loads(body)
|
|
# dump each to a file for inspection
|
|
ts = time.time()
|
|
with open(f"browser_login/output/inspect_{ts}.json", "w", encoding="utf-8") as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
|
|
if isinstance(data, dict):
|
|
print("Keys:", list(data.keys()))
|
|
if 'result' in data:
|
|
res = data['result']
|
|
if isinstance(res, dict):
|
|
print("Result Keys:", list(res.keys()))
|
|
else:
|
|
print("Result is list/other")
|
|
elif 'rows' in data:
|
|
print("Rows length:", len(data['rows']))
|
|
except Exception as e:
|
|
print("Error parsing:", e)
|