From c651a3f6da8ddb726d4b04d1160b57117aa5bb38 Mon Sep 17 00:00:00 2001 From: weitzu-com <72116249+weitzu-com@users.noreply.github.com> Date: Sun, 9 Aug 2026 07:30:23 +0800 Subject: [PATCH] fix(wechat): improve image extraction and HTML entity cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix incomplete image extraction: add three-method SSR image fallback (window.picture_page_info_list regex + cgiDataNew JSON + global cdn_url scan) Fixes image articles (type 8) only recovering 5/12 images - Add html.unescape() to _process_text_block to clean residual HTML entities in WeChat topic links (<a class=wx_topic_link...> → #GEO) - Strip HTML tags from text content keeping only inner hashtag text - Add _extract_ssr_images helper with three-tier extraction strategy - Improve parse_ssr_content: add meta description fallback for text when SSR data lacks desc/content_noencode fields - Merge SSR images into DOM-parsed content when js_content exists Closes image extraction gap: 5→12 images for type-8 articles --- .../news-extractor/scripts/crawlers/wechat.py | 153 ++++++++++++++---- 1 file changed, 126 insertions(+), 27 deletions(-) diff --git a/.claude/skills/news-extractor/scripts/crawlers/wechat.py b/.claude/skills/news-extractor/scripts/crawlers/wechat.py index 85b8fac..816b717 100644 --- a/.claude/skills/news-extractor/scripts/crawlers/wechat.py +++ b/.claude/skills/news-extractor/scripts/crawlers/wechat.py @@ -5,6 +5,7 @@ from __future__ import annotations import hashlib +import html import json import logging import re @@ -171,8 +172,54 @@ def parse_html_to_news_content(self, html_content: str) -> List[ContentItem]: self._process_content_node(node) contents = [item for item in self._contents if item.content.strip()] + + # Also extract images from SSR data (image articles have most images there) + ssr_images = self._extract_ssr_images(html_content) + existing_image_urls = {item.content for item in contents if item.type == ContentType.IMAGE} + for ssr_img in ssr_images: + if ssr_img.content not in existing_image_urls: + contents.insert(0, ssr_img) + existing_image_urls.add(ssr_img.content) + return self._remove_duplicate_contents(contents) + def _extract_ssr_images(self, html_content: str) -> List[ContentItem]: + """Extract images from SSR/embedded data (covers image articles type 8). + + WeChat image articles store most images inside inline