Skill: lcwatergm-afk/weixin-article-read (version 1.0.0)

--- name: weixin-article-read description: 读取微信公众平台文章内容（mp.weixin.qq.com）。当用户发送微信文章链接、需要读取微信文章内容、提取公众号文章时自动激活。支持突破微信反爬限制，获取完整文章文本。 --- # 微信文章读取技能 ## 功能说明 读取微信公众平台（mp.weixin.qq.com）文章内容，突破反爬限制，还原干净的文章文本。 ## 使用场景 - 用户发送微信文章链接，需要读取内容 - 需要提取公众号文章进行总结、分析 - 微信文章链接需要突破反爬获取原文 ## 核心脚本 ```bash # 使用方法 python3 scripts/read_weixin_article.py <微信文章URL> # 示例 python3 scripts/read_weixin_article.py "https://mp.weixin.qq.com/s/kItlJmjOnq6p6tXtYGHrGQ" ``` ## 技术实现 1. 使用 `curl` 模拟移动端 User-Agent 获取页面 2. 使用 BeautifulSoup 解析HTML 3. 提取 `id="js_content"` 或 `class="rich_media_content"` 的文章主体 4. 清理脚本、样式等干扰元素，还原干净文本 ## 注意事项 - 微信文章有反爬限制，必须使用移动端 User-Agent - 部分文章可能因权限问题无法完整获取 - 成功读取后记得向用户确认内容是否正确

path: scripts/read_weixin_article.py
content: #!/usr/bin/env python3
"""
WeChat Article Reader - Read articles from mp.weixin.qq.com
Usage: python3 read_weixin_article.py <url>
"""

import sys
import os
import re

try:
    from bs4 import BeautifulSoup
except ImportError:
    print("Error: beautifulsoup4 not installed. Run: pip3 install beautifulsoup4")
    sys.exit(1)

def read_weixin_article(url):
    """Read a WeChat article and return clean text content."""
    
    headers = {
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }
    
    # Use curl to fetch the page
    cmd = f'curl -s -L --max-time 20'
    for key, value in headers.items():
        cmd += f' -H "{key}: {value}"'
    cmd += f' "{url}"'
    
    import subprocess
    result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
    
    if result.returncode != 0:
        return f"Error fetching URL: {result.stderr}"
    
    html = result.stdout
    
    # Parse HTML with BeautifulSoup
    soup = BeautifulSoup(html, 'html.parser')
    
    # Remove script and style elements
    for tag in soup(['script', 'style']):
        tag.decompose()
    
    # Try to find the article content
    # Method 1: Look for id="js_content" (new WeChat format)
    article = soup.find('div', id='js_content')
    
    if not article:
        # Method 2: Look for class="rich_media_content"
        article = soup.find('div', class_='rich_media_content')
    
    if not article:
        # Method 3: Look for any common article content areas
        article = soup.find('div', class_=re.compile(r'.*article.*', re.I))
    
    if not article:
        # Method 4: Try to get the title and meta description
        title = soup.find('meta', property='og:title')
        desc = soup.find('meta', property='og:description')
        if title and desc:
            return f"标题: {title.get('content', 'N/A')}\n\n摘要: {desc.get('content', 'N/A')}\n\n(无法提取完整内容)"
    
    # Get text content
    text = article.get_text(separator='\n', strip=True)
    
    # Clean up excessive newlines
    text = re.sub(r'\n{3,}', '\n\n', text)
    
    # Also try to get the title
    title_tag = soup.find('meta', property='og:title')
    title = title_tag.get('content', '') if title_tag else ''
    
    return f"# {title}\n\n{text}" if title else text

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python3 read_weixin_article.py <wechat-article-url>")
        sys.exit(1)
    
    url = sys.argv[1]
    content = read_weixin_article(url)
    print(content)

Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)