|
|
@@ -214,11 +214,17 @@ def collect_notes(publisher, limit=10):
|
|
|
return notes[:limit]
|
|
|
|
|
|
|
|
|
-def screenshot_current(publisher, output_path):
|
|
|
- """用 CDP 截取当前页面(JPEG)。"""
|
|
|
+def screenshot_current(publisher, output_path, full_page: bool = True):
|
|
|
+ """用 CDP 截取当前页面(JPEG),默认整页截图。
|
|
|
+
|
|
|
+ full_page=True 时用 captureBeyondViewport 截取整个可滚动页面。
|
|
|
+ """
|
|
|
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
|
|
- result = publisher._send("Page.captureScreenshot", {"format": "jpeg", "quality": 60})
|
|
|
- # CDP 对 captureScreenshot 返回 {"data": "<base64>"}(_send 已剥掉 result 包装)
|
|
|
+ params = {"format": "jpeg", "quality": 60}
|
|
|
+ if full_page:
|
|
|
+ params["captureBeyondViewport"] = True
|
|
|
+ result = publisher._send("Page.captureScreenshot", params)
|
|
|
+
|
|
|
data = result.get("data") or (result.get("result") or {}).get("data")
|
|
|
if data:
|
|
|
img_data = base64.b64decode(data)
|
|
|
@@ -229,6 +235,38 @@ def screenshot_current(publisher, output_path):
|
|
|
raise RuntimeError(f"截图失败: {result}")
|
|
|
|
|
|
|
|
|
+# 账号概览页 URL(创作者中心数据看板)
|
|
|
+ACCOUNT_OVERVIEW_URL = "https://creator.xiaohongshu.com/statistics/account/v2"
|
|
|
+
|
|
|
+
|
|
|
+def capture_three_screenshots(publisher, shot_dir, prefix="xhs_bot"):
|
|
|
+ """依次截取三张整页截图:首页 / 笔记管理 / 账号概览。
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ list[str]: 三张截图的文件路径(按顺序:首页, 笔记管理, 账号概览)
|
|
|
+ """
|
|
|
+ os.makedirs(shot_dir, exist_ok=True)
|
|
|
+ ts = int(time.time())
|
|
|
+ shots = []
|
|
|
+
|
|
|
+ targets = [
|
|
|
+ (CREATOR_HOME, f"{prefix}_{ts}_home.jpg"),
|
|
|
+ (NOTES_MANAGE_URL, f"{prefix}_{ts}_notes.jpg"),
|
|
|
+ (ACCOUNT_OVERVIEW_URL, f"{prefix}_{ts}_overview.jpg"),
|
|
|
+ ]
|
|
|
+ for url, fname in targets:
|
|
|
+ try:
|
|
|
+ publisher._navigate(url)
|
|
|
+ time.sleep(5)
|
|
|
+ path = os.path.join(shot_dir, fname)
|
|
|
+ screenshot_current(publisher, path, full_page=True)
|
|
|
+ shots.append(path)
|
|
|
+ except Exception as e:
|
|
|
+ _log(f"[WARN] 截图失败 {url}: {e}")
|
|
|
+
|
|
|
+ return shots
|
|
|
+
|
|
|
+
|
|
|
def append_daily_record(date, overview, notes):
|
|
|
"""追加当日快照到本地 JSON 记录(轻量,不依赖旧 CSV 结构)。"""
|
|
|
os.makedirs(RECORD_DIR, exist_ok=True)
|
|
|
@@ -291,21 +329,19 @@ def main():
|
|
|
notes = collect_notes(publisher, args.limit)
|
|
|
_log(f" 采集到 {len(notes)} 篇笔记")
|
|
|
|
|
|
- # 说明:新版创作者中心已无汇总"未回复评论"独立页面,评论数据
|
|
|
- # 体现在每篇笔记的 comment_count 中;如需每篇未回复详情需进单篇详情页。
|
|
|
|
|
|
- _log("截图(笔记管理页)...")
|
|
|
- shot_path = os.path.join(SCREENSHOT_DIR, f"xhs_daily_{date}.jpg")
|
|
|
- screenshot_current(publisher, shot_path)
|
|
|
+ _log("截图(首页/笔记管理/账号概览 三张整页)...")
|
|
|
+ shot_paths = capture_three_screenshots(publisher, SCREENSHOT_DIR, prefix=f"xhs_daily_{date}")
|
|
|
+ _log(f" 截图 {len(shot_paths)} 张")
|
|
|
+
|
|
|
|
|
|
- # 5. 本地记录
|
|
|
append_daily_record(date, overview, notes)
|
|
|
|
|
|
- # 6. 飞书推送
|
|
|
+
|
|
|
_log("推送到飞书...")
|
|
|
sys.path.insert(0, OPERATION_DIR)
|
|
|
from xhs_feishu import send_daily_report
|
|
|
- send_daily_report(CONFIG_PATH, date, overview, notes, screenshot_path=shot_path)
|
|
|
+ send_daily_report(CONFIG_PATH, date, overview, notes, screenshot_paths=shot_paths)
|
|
|
_log("✅ 日报流程完成")
|
|
|
|
|
|
except Exception as e:
|