labali-wechat-download-article
MANDATORY — load
references/plan.mdbefore any browser or extraction action begins.
⚠️ NEVER WRITE YOUR OWN SCRIPT
The download logic is fully implemented. Always invoke the existing script — do NOT write a new one.
cd /Users/kingsonwu/programming/kingson4wu/labali-skills
npx tsx skills/private/labali-wechat-download-article/scripts/run.ts \
--post_url "<url>" \
--output_dir "$HOME/Downloads/wechat"
The sections below are implementation documentation for the script itself, not instructions for you to re-implement. If the script doesn't exist or can't run, report the error — never substitute with hand-written Playwright code.
Required Constraints
- Use browser automation only (Playwright over CDP).
- Reuse authenticated Chrome session via CDP startup:
open -na "Google Chrome" --args --remote-debugging-port=9223 --user-data-dir="$HOME/.chrome-labali-no-proxy" --no-proxy-server - Extract article content from WeChat DOM: title, account name, author, publish time, content text, images.
- Images are lazy-loaded via
data-src— always preferdata-srcoversrc. - Download only images from
mmbiz.qpic.cn(skip avatars frommmbiz.qlogo.cn). - Generate
article.mdwith metadata and image references. - Do not generate a manifest file.
WeChat Article Structure
WeChat public account articles (mp.weixin.qq.com/s/...) use this DOM structure:
- Title:
#activity-nameor.rich_media_title - Account (WeChat Official Account):
#js_nameor.account_nickname_inner - Publish time:
#publish_time(format:YYYY-MM-DD) - Content:
#js_content— the main article body - Images:
#js_content img[data-src]— lazy-loaded content images
WeChat articles are mostly public pages. Login is only required for member-only or private content.
Anti-Detection Principles
- If a WeChat tab is already open, reuse it — do not open a new tab or navigate away from other tabs.
- After
page.goto(), wait 1.5–2.5 seconds (randomized) before extracting. - Do not issue parallel HTTP requests for images — download sequentially with 200–500ms random delays.
NEVER
- Never write a custom Playwright/Node.js script — the existing
scripts/run.tshandles all extraction. - Never launch a new Chrome instance if CDP is already responding on port 9223.
- Never take over a non-WeChat browser tab — find a WeChat tab to reuse, or open a new tab.
- Never use
srcalone for WeChat image extraction — WeChat lazy-loads viadata-src; missing this yields 0 images. - Never retry automatically after a login wall — pause and prompt the user to log in.
- Never report success if
article.mdwas not generated.
Success Criteria
A run is successful only when all conditions hold:
- An article output folder is created under the specified local directory.
- Folder naming format is
<download_date>-<sanitized_title>-<article_id>(title omitted when empty). article.mdis generated with title, account, publish time, source URL, and image references.- All
mmbiz.qpic.cnimages from the article content are saved. - Partial image failure is acceptable — report failed URLs without throwing.
Operational Mode
- Startup:
- Check if CDP is responding:
curl -s http://localhost:9223/json/version - If not → auto-launch Chrome (no user prompt needed), wait 3s, verify
- If already running → reuse
- Check if CDP is responding:
- Tab management:
- Find existing WeChat tab → reuse (navigate to article URL)
- No WeChat tab → open new tab
- If login wall detected → prompt user to log in manually; wait for confirmation
Resources
| When | Must load |
|---|---|
| Always — at skill invocation start | references/plan.md |
| Image extraction returns 0 images | Check data-src vs src; check if page scrolled enough for lazy load |