wechat-article-parser 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/.gitignore +1 -0
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/PKG-INFO +1 -1
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/pyproject.toml +1 -1
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/src/wechat_article_parser/parser.py +28 -9
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/tests/test_parser.py +1 -0
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/LICENSE +0 -0
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/README.md +0 -0
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/src/wechat_article_parser/__init__.py +0 -0
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/src/wechat_article_parser/models.py +0 -0
- {wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/tests/conftest.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "wechat-article-parser"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.2"
|
|
8
8
|
description = "WeChat MP article parser - extract metadata and content from WeChat public account articles"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
{wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/src/wechat_article_parser/parser.py
RENAMED
|
@@ -236,18 +236,37 @@ def _extract_rich_media_content(content_tag: Tag, result: ArticleResult) -> None
|
|
|
236
236
|
tag.decompose()
|
|
237
237
|
|
|
238
238
|
# 处理含有 background-image 的 <svg> 标签
|
|
239
|
-
#
|
|
239
|
+
# 部分文章用嵌套 SVG(外层 SVG > foreignobject > 内层 SVG)承载正文图片,
|
|
240
|
+
# 需从外向内收集所有图片 URL,一次性替换为多个 <img> 标签
|
|
240
241
|
to_remove = []
|
|
241
|
-
for svg in soup.find_all("svg"):
|
|
242
|
-
|
|
243
|
-
if
|
|
242
|
+
for svg in soup.find_all("svg", recursive=True):
|
|
243
|
+
# 跳过已被外层 SVG 处理过的嵌套 SVG(已脱离文档树)
|
|
244
|
+
if not svg.parent:
|
|
245
|
+
continue
|
|
246
|
+
# 跳过嵌套在其他 SVG 内的 SVG,由外层统一处理
|
|
247
|
+
if svg.find_parent("svg"):
|
|
248
|
+
continue
|
|
249
|
+
|
|
250
|
+
# 收集本 SVG 及所有后代 SVG 中的 background-image 图片
|
|
251
|
+
all_svgs = [svg] + svg.find_all("svg")
|
|
252
|
+
img_tags = []
|
|
253
|
+
for s in all_svgs:
|
|
254
|
+
style = s.get("style", "")
|
|
255
|
+
if "background-image" not in style:
|
|
256
|
+
continue
|
|
244
257
|
m = re.search(r'url\("([^"]+)"\)', style)
|
|
245
|
-
if m:
|
|
246
|
-
normalized = _normalize_image_url(m.group(1))
|
|
247
|
-
new_img = soup.new_tag("img", src=normalized)
|
|
248
|
-
svg.replace_with(new_img)
|
|
258
|
+
if not m:
|
|
249
259
|
continue
|
|
250
|
-
|
|
260
|
+
normalized = _normalize_image_url(m.group(1))
|
|
261
|
+
img_tags.append(soup.new_tag("img", src=normalized))
|
|
262
|
+
if normalized not in seen:
|
|
263
|
+
seen.add(normalized)
|
|
264
|
+
result.images.append(normalized)
|
|
265
|
+
|
|
266
|
+
if img_tags:
|
|
267
|
+
svg.replace_with(*img_tags)
|
|
268
|
+
else:
|
|
269
|
+
to_remove.append(svg)
|
|
251
270
|
for tag in to_remove:
|
|
252
271
|
tag.decompose()
|
|
253
272
|
|
|
File without changes
|
|
File without changes
|
{wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/src/wechat_article_parser/__init__.py
RENAMED
|
File without changes
|
{wechat_article_parser-0.0.1 → wechat_article_parser-0.0.2}/src/wechat_article_parser/models.py
RENAMED
|
File without changes
|
|
File without changes
|