|
|
@@ -105,6 +105,56 @@ def delete_monitor(uid: str) -> bool:
|
|
|
return True
|
|
|
|
|
|
|
|
|
+def _parse_profile_html(body: str) -> dict:
|
|
|
+ """从 profile 页 SSR HTML 抠资料(M8 web 版):user_name + ownerCount。
|
|
|
+
|
|
|
+ 页面无作品列表(C4 已证),但用户资料是服务端渲染内嵌的——
|
|
|
+ `"user_name":"泽小泽_"`、`"ownerCount":{"fan":…,"follow":…,"photo_public":…}`。
|
|
|
+ """
|
|
|
+ d = {}
|
|
|
+ m = re.search(r'"user_name":"([^"]*)"', body or '')
|
|
|
+ if m:
|
|
|
+ d['name'] = m.group(1)
|
|
|
+ i = (body or '').find('ownerCount')
|
|
|
+ if i >= 0:
|
|
|
+ seg = body[i:i + 300]
|
|
|
+ for key, out in (('fan', 'fensishu'), ('follow', 'guanzhushu'),
|
|
|
+ ('photo_public', 'zuopinshu')):
|
|
|
+ mm = re.search(rf'"{key}":(\d+)', seg)
|
|
|
+ if mm:
|
|
|
+ d[out] = int(mm.group(1))
|
|
|
+ return d
|
|
|
+
|
|
|
+
|
|
|
+def refresh_monitor_stats_web(cfg, uid: str = None) -> int:
|
|
|
+ """资料刷新(web 版):抓 profile 页 SSR HTML 抠 ownerCount 落库。
|
|
|
+
|
|
|
+ az3-api 版 refresh_monitor_stats 需 APP 型 did(result=40,联调清单C3),
|
|
|
+ 此为白盒可行路径;用 anchor 首行的网页CK请求。返回成功刷新数。
|
|
|
+ """
|
|
|
+ import requests as _rq
|
|
|
+ from .httpclient import WEB_UA
|
|
|
+ rows = (db.query('SELECT uid FROM monitoring WHERE uid=?', (uid,)) if uid
|
|
|
+ else db.query('SELECT uid FROM monitoring ORDER BY id'))
|
|
|
+ ck_rows = db.query('SELECT cookie1 FROM anchor ORDER BY id LIMIT 1')
|
|
|
+ cookie = ck_rows[0]['cookie1'] if ck_rows else ''
|
|
|
+ n = 0
|
|
|
+ for r in rows:
|
|
|
+ try:
|
|
|
+ resp = _rq.get(f'https://www.kuaishou.com/profile/{r["uid"]}',
|
|
|
+ headers={'Cookie': cookie, 'User-Agent': WEB_UA},
|
|
|
+ timeout=20)
|
|
|
+ d = _parse_profile_html(resp.text)
|
|
|
+ if not (d.get('name') or d.get('fensishu') is not None):
|
|
|
+ continue # 页面无资料(UID错/风控页)
|
|
|
+ d['uid'] = r['uid']
|
|
|
+ update_monitor_stats(d)
|
|
|
+ n += 1
|
|
|
+ except Exception:
|
|
|
+ continue # 单账号失败不中断批次
|
|
|
+ return n
|
|
|
+
|
|
|
+
|
|
|
def refresh_monitor_stats(cfg, uid: str = None) -> int:
|
|
|
"""资料查询刷新监控账号统计(E线 M8:az3-api profile,iOS伪装)。
|
|
|
|