← 返回
未分类

微信公众号文章_转_PDF

Convert WeChat public account (mp.weixin.qq.com) articles to PDF files with full content, formatting, and image preservation. This skill should be used when users want to save, export, archive, or convert WeChat articles to PDF format, or when users provide a WeChat article URL and want a local PDF copy.
Convert WeChat public account (mp.weixin.qq.com) articles to PDF files with full content, formatting, and image preservation. This skill should be used when users want to save, export, archive, or convert WeChat articles to PDF format, or when users provide a WeChat article URL and want a local PDF copy.
何积极
未分类 community v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 61
下载
💾 0
安装
1
版本
#latest

概述

WeChat Article to PDF

Convert WeChat public account articles to high-fidelity PDF files, preserving original content, formatting, layout, and images.

Quick Start

To convert a WeChat article, run the bundled script:

python D:\wechat-to-pdf\scripts\wechat_to_pdf.py <URL> [-o OUTPUT] [-f FORMAT] [-t TIMEOUT]

Workflow

When a user provides a WeChat article URL for PDF conversion, follow these steps:

Step 1: Validate Input

Verify the URL belongs to mp.weixin.qq.com. Reject non-WeChat URLs with a clear explanation. Accepted URL patterns:

  • https://mp.weixin.qq.com/s/...
  • https://mp.weixin.qq.com/s?__biz=...

Step 2: Check Dependencies

Before executing, confirm playwright is installed. If missing, run:

pip install playwright
python -m playwright install chromium

Step 3: Determine Output Path

  • If the user specifies a file path or directory, pass it via the -o argument
  • If not specified, the script auto-names the PDF using the article title and saves to the current working directory

Step 4: Execute Conversion

Run the conversion script with appropriate arguments:

python D:\wechat-to-pdf\scripts\wechat_to_pdf.py "<URL>" -o "<output_path>" -f <format>

The script handles all conversion steps internally:

  1. Opens the article in headless Chromium
  2. Waits for content to load
  3. Scrolls the page to trigger lazy-loaded images
  4. Fixes WeChat's data-src lazy-loading mechanism
  5. Injects CSS to hide non-article elements (comments, toolbars, QR codes)
  6. Generates PDF with proper margins and background colors

Step 5: Verify Output

After execution, confirm:

  • The script exited with code 0
  • Report the output file path and size to the user

Command Reference

| Argument | Short | Required | Default | Description |

| ----------- | ----- | -------- | ------------------- | -------------------------------------------- |

| url | - | Yes | - | WeChat article URL |

| --output | -o | No | {cwd}/{title}.pdf | Output file path or directory |

| --format | -f | No | A4 | Paper format: A4, A3, Letter, Legal, Tabloid |

| --timeout | -t | No | 60 | Page load timeout in seconds |

Exit Codes

| Code | Meaning |

| ---- | --------------------------------------------- |

| 0 | Success |

| 1 | Argument error |

| 2 | Invalid URL (not a WeChat article) |

| 3 | Missing dependency (playwright not installed) |

| 4 | Page load failure (timeout, network error) |

| 5 | PDF generation failure |

Error Handling

| Scenario | Action |

| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- |

| Non-WeChat URL | Inform user that only mp.weixin.qq.com URLs are supported |

| Network timeout | Suggest checking network connection or increasing timeout with -t |

| Playwright not installed | Provide installation commands |

| Images missing in PDF | The script already handles lazy-loading; if issues persist, refer to references/wechat-css-selectors.md for DOM structure updates |

Bundled Resources

  • scripts/wechat_to_pdf.py - Core conversion script. Accepts CLI arguments, validates URLs, handles lazy-loaded images, and generates PDF via Playwright headless Chromium.
  • references/wechat-css-selectors.md - Documents WeChat article page DOM structure, CSS selectors for hidden elements, and the image lazy-loading mechanism. Consult this file when WeChat page structure changes break the conversion.

版本历史

共 1 个版本

  • v1.0.0 初步发布 当前
    2026-05-23 10:02 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

office-efficiency

Nano Pdf

steipete
使用nano-pdf CLI通过自然语言指令编辑PDF
★ 281 📥 117,104
office-efficiency

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 392 📥 148,349
office-efficiency

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 468 📥 156,080