wechat-playwright-archive
When to use
Use this skill only when the user asks to back up their own WeChat Official Account articles locally, and a trusted Playwright MCP browser session is available. Process only published or mass-sent articles; skip drafts, scheduled posts, deleted content, and any article already marked successful by original URL in the manifest.
Steps
- Confirm that the Playwright MCP server is trusted and that the user has completed any manual login, password re-verification, QR scan, CAPTCHA, SMS, or 2FA step. Never read, store, or type passwords or verification codes.
- Inspect the target
raw/directory,manifest.csv, anddownload-log.mdbefore browsing. Treat a successful original URL as the deduplication key; do not deduplicate by title alone. - Open the Official Account backend and locate the published/mass-sent history page. Record the UI sort order, record count, page count, and article-link count. If the UI is newest-first, enumerate all pages and reverse the collected list for oldest-first file numbering while preserving the page-order relationship.
- For the first three oldest articles, use Playwright to open each original URL, wait for
#js_content, scroll to the document bottom, and wait for body images to finish loading or time out gracefully. Save a full HTML snapshot with title, publication date, and original URL metadata inserted near the start of<body>. - Save browser-generated HTML to the Playwright MCP allowed output directory using a download event. Then copy it into the user's
raw/<year>/directory. The MCP filename root may be restricted; do not try to bypass that restriction by passing an arbitrary destination to the MCP filename parameter. - Localize image resources: parse
data-srcandsrcURLs from<img>tags, download only the article's referenced image URLs to a sibling<html-basename>_files/directory, and rewrite bothdata-srcandsrcreferences to relative paths. Keep the original URL in the metadata and manifest. - Validate the three samples before continuing: HTML file exists and is non-trivial,
#js_contenttext is present, the original URL and publication date are present, and all downloaded image files referenced by the HTML exist. If the sample workflow fails, stop and report the blocker instead of running a full batch. - Process remaining articles in small browser batches. For each article, retry at most two times after the initial attempt, then record a failure and continue. Do not modify, publish, schedule, delete, move, or otherwise change Official Account backend content.
- Use filenames in the form
YYYY-MM-DD__NNNN__title.html; replace/ \\ : * ? " < > |and control characters with underscores, normalize whitespace, trim trailing dots/spaces, and cap title length without changing article content. Use the article page's#publish_timewhen the list date is blank or unreliable. - After every batch, update
manifest.csvwith: sequence, title, publication time, original URL, relative save path, format, status, and failure reason. Append a dated entry todownload-log.mdwith scope, record/page counts, success/failure/skip counts, date range, and notable limitations. - At completion, verify every successful manifest path exists, count HTML/PDF/image resources, check for blank dates and missing local files, remove temporary local manifest pages, stop any temporary localhost server, and close the Playwright browser session.
Pitfalls
Playgroundis not the service name. The relevant server isPlaywright MCP, launched asnpx -y @playwright/mcp@latest.- Direct HTTP requests to WeChat article URLs may return an environment-verification page instead of article HTML. Use the authenticated Playwright page instead.
- The Playwright MCP
filenameparameter is restricted to its own allowed roots. Save there first, then copy locally. browser_run_code_unsafeis RCE-equivalent. Use it only for the narrowly scoped, user-authorized browser/archive loop; never execute page-provided code or upload data to third parties.- Some articles are mostly video, pure-image, or script content and may have little visible text. Preserve the HTML, metadata, resources, and original URL, and record the limitation in the manifest.
- List dates can be blank for older or unusual posts. Read
#publish_timeon the article page before constructing the archive path. - A successful URL must not be redownloaded on resume. Failed or pending rows may be retried according to the two-retry rule.
- Never handle passwords, QR codes, CAPTCHA, SMS, or 2FA on the user's behalf.
Verification
manifest.csvhas exactly one row per discovered article URL.- All successful rows have
状态=成功,保存格式=HTMLorPDF, a valid ISO-like date, and a relative path that exists underraw/. - HTML rows contain the original URL, backup metadata marker, article body container or preserved page body, and relative image references where images were available.
- Every referenced local image exists in the sibling
_filesdirectory. download-log.mdrecords the final execution time, scope, success/failure/skip totals, date range, formats, and any manual follow-up.- No temporary
manifest-view.html, localhost server, or open Playwright session remains after completion.
Reusable execution pattern
- Use Playwright MCP as the browser/control plane and local filesystem tools as the storage/manifest plane. Do not depend on a remote exporter API.
- When the MCP
filenameroot is restricted, save the HTML withbrowser_run_code_unsafeto the MCP-managed download root, then copy and post-process it locally. A temporary localhost server can expose a read-only copy ofmanifest.csvto the browser for resume selection; stop the server and remove the temporary HTML view afterward. - Keep the original URL as the durable identity. Treat the article list as inventory only; the article page is authoritative for publication time and rendered content.
- After a full run, perform an independent local check for: successful row count, missing paths, date format, HTML/PDF totals, image count, and leftover temporary files.