parsehub 2.4.1__tar.gz → 2.4.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.
- {parsehub-2.4.1/src/parsehub.egg-info → parsehub-2.4.2}/PKG-INFO +2 -1
- {parsehub-2.4.1 → parsehub-2.4.2}/README.md +1 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/pyproject.toml +1 -1
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/__init__.py +1 -0
- parsehub-2.4.2/src/parsehub/parsers/parser/jandan.py +35 -0
- parsehub-2.4.2/src/parsehub/provider_api/jandan.py +104 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/types/platform.py +1 -0
- {parsehub-2.4.1 → parsehub-2.4.2/src/parsehub.egg-info}/PKG-INFO +2 -1
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub.egg-info/SOURCES.txt +2 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/test/test_core_offline.py +6 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/LICENSE +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/setup.cfg +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/__init__.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/__init__.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/cli.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/cli_config.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/config/__init__.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/config/config.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/errors.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/__init__.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/base/__init__.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/base/base.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/base/ytdlp.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/bangumi.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/bilibili.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/coolapk.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/douban.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/douyin.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/facebook.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/instagram.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/kuaishou.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/medium.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/pipix.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/snapchat.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/threads.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/tieba.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/tiktok.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/toutiao.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/twitter.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/weibo.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/weixin.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/wxchannels.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/xhs.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/xiaoheihe.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/youtube.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/zhihu.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/parsers/parser/zuiyou.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/__init__.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/bangumi.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/bilibili.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/coolapk.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/douban.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/douyin.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/instagram.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/kuaishou.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/medium.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/pipix.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/threads.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/tieba.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/tiktok.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/toutiao.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/twitter.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/weibo.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/weixin.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/wxchannels.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/xhs.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/xiaoheihe.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/zhihu.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/provider_api/zuiyou.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/types/__init__.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/types/callback.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/types/media_file.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/types/media_ref.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/types/post.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/types/result.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/utils/downloader.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/utils/fallback.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/utils/helpers.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub/utils/media_info.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub.egg-info/dependency_links.txt +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub.egg-info/entry_points.txt +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub.egg-info/requires.txt +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/src/parsehub.egg-info/top_level.txt +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/test/test_cli.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/test/test_cli_config.py +0 -0
- {parsehub-2.4.1 → parsehub-2.4.2}/test/test_downloader.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: parsehub
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.2
|
|
4
4
|
Summary: 轻量、异步、开箱即用的社交媒体聚合解析库
|
|
5
5
|
Author-email: 梓澪 <zilingmio@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -101,6 +101,7 @@ Dynamic: license-file
|
|
|
101
101
|
| **Bangumi** | | ✅ | 💬 条目讨论, 日志, 小组话题 |
|
|
102
102
|
| **今日头条** | ✅ | ✅ | 📰 文章, 微头条 |
|
|
103
103
|
| **Medium** | ✅ | ✅ | 📰 文章 |
|
|
104
|
+
| **煎蛋** | | ✅ | 📰 文章, 💬 话题 |
|
|
104
105
|
|
|
105
106
|
## 📦 安装
|
|
106
107
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from pathlib import PurePosixPath
|
|
2
|
+
from urllib.parse import urlsplit
|
|
3
|
+
|
|
4
|
+
from ...provider_api.jandan import Jandan, JandanError
|
|
5
|
+
from ...types import AniRef, ImageRef, ParseError, Platform, RichTextParseResult
|
|
6
|
+
from ..base.base import BaseParser
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class JandanParser(BaseParser):
|
|
10
|
+
__platform__ = Platform.JANDAN
|
|
11
|
+
__supported_type__ = ["图文"]
|
|
12
|
+
__match__ = r"^(http(s)?://)?jandan\.net/(t|p)/\d+"
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def _ref(url: str) -> ImageRef | AniRef:
|
|
16
|
+
"""正文里的动图也是 <img>; 扩展名取自 URL."""
|
|
17
|
+
suffix = PurePosixPath(urlsplit(url).path).suffix.lstrip(".").lower()
|
|
18
|
+
if suffix == "gif":
|
|
19
|
+
return AniRef(url=url)
|
|
20
|
+
return ImageRef(url=url, ext=suffix) if suffix else ImageRef(url=url)
|
|
21
|
+
|
|
22
|
+
async def _do_parse(self, raw_url: str) -> RichTextParseResult:
|
|
23
|
+
try:
|
|
24
|
+
post = await Jandan(proxy=self.proxy).parse(raw_url)
|
|
25
|
+
except JandanError as e:
|
|
26
|
+
raise ParseError(f"煎蛋解析失败: {e}") from e
|
|
27
|
+
|
|
28
|
+
return RichTextParseResult(
|
|
29
|
+
title=post.title,
|
|
30
|
+
media=[self._ref(url) for url in post.images],
|
|
31
|
+
markdown_content=post.markdown_content,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
__all__ = ["JandanParser"]
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from typing import Any
|
|
6
|
+
from urllib.parse import urljoin
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
from bs4 import BeautifulSoup
|
|
10
|
+
from markdownify import MarkdownConverter
|
|
11
|
+
|
|
12
|
+
from ..errors import ContentUnavailableError
|
|
13
|
+
from ..utils.helpers import UA
|
|
14
|
+
|
|
15
|
+
_POST_NO_RE = re.compile(r"No\.\s*\d+")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class JandanPost:
|
|
20
|
+
"""煎蛋帖子的解析结果
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
title: 标题
|
|
24
|
+
markdown_content: markdown 正文
|
|
25
|
+
images: 正文内的图片地址
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
title: str
|
|
29
|
+
markdown_content: str
|
|
30
|
+
images: list[str] = field(default_factory=list)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Jandan:
|
|
34
|
+
def __init__(self, proxy: str | None = None):
|
|
35
|
+
self.proxy = proxy
|
|
36
|
+
|
|
37
|
+
async def parse(self, url: str) -> JandanPost:
|
|
38
|
+
async with httpx.AsyncClient(proxy=self.proxy, timeout=30, headers={"User-Agent": UA}) as client:
|
|
39
|
+
response = await client.get(url)
|
|
40
|
+
if response.status_code == 404:
|
|
41
|
+
raise ContentUnavailableError("煎蛋内容不存在或已删除")
|
|
42
|
+
if not 200 <= response.status_code < 300:
|
|
43
|
+
raise JandanError(f"HTTP {response.status_code}")
|
|
44
|
+
return self._parse_html(response.text, str(response.url))
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def _parse_html(html: str, page_url: str) -> JandanPost:
|
|
48
|
+
soup = BeautifulSoup(html, "lxml")
|
|
49
|
+
content = soup.select_one(".post-content")
|
|
50
|
+
if content is None:
|
|
51
|
+
raise JandanError("未找到煎蛋正文")
|
|
52
|
+
|
|
53
|
+
heading = soup.find("h1")
|
|
54
|
+
for a in content.find_all("a", href=True):
|
|
55
|
+
a["href"] = urljoin(page_url, str(a["href"]))
|
|
56
|
+
converter = _JandanMarkdownConverter(page_url)
|
|
57
|
+
markdown_content = converter.convert(str(content)).strip()
|
|
58
|
+
return JandanPost(
|
|
59
|
+
title=_compose_title(
|
|
60
|
+
heading.get_text(strip=True) if heading else "",
|
|
61
|
+
_first_line(content.get_text("\n", strip=True)),
|
|
62
|
+
),
|
|
63
|
+
markdown_content=markdown_content,
|
|
64
|
+
images=converter.images,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _first_line(text: str, limit: int = 80) -> str:
|
|
69
|
+
line = next((line for line in text.splitlines() if line.strip()), "")
|
|
70
|
+
return " ".join(line.split())[:limit]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _compose_title(heading: str, first_line: str) -> str:
|
|
74
|
+
"""话题帖的标题只是 "No.6209188", 这时用正文首行代替."""
|
|
75
|
+
heading = " ".join(heading.split())
|
|
76
|
+
if heading and not _POST_NO_RE.fullmatch(heading):
|
|
77
|
+
return heading
|
|
78
|
+
return first_line or heading
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class _JandanMarkdownConverter(MarkdownConverter):
|
|
82
|
+
"""把正文 HTML 转为 markdown 并收集图片地址."""
|
|
83
|
+
|
|
84
|
+
def __init__(self, page_url: str) -> None:
|
|
85
|
+
super().__init__(heading_style="ATX")
|
|
86
|
+
self.page_url = page_url
|
|
87
|
+
self.images: list[str] = []
|
|
88
|
+
|
|
89
|
+
def convert_img(self, el: Any, text: Any, parent_tags: Any) -> str:
|
|
90
|
+
alt = el.attrs.get("alt") or ""
|
|
91
|
+
source = el.attrs.get("src") or ""
|
|
92
|
+
url = urljoin(self.page_url, source) if source else ""
|
|
93
|
+
if not url:
|
|
94
|
+
return alt
|
|
95
|
+
if url not in self.images:
|
|
96
|
+
self.images.append(url)
|
|
97
|
+
return f""
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class JandanError(Exception):
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
__all__ = ["Jandan", "JandanError", "JandanPost"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: parsehub
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.2
|
|
4
4
|
Summary: 轻量、异步、开箱即用的社交媒体聚合解析库
|
|
5
5
|
Author-email: 梓澪 <zilingmio@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -101,6 +101,7 @@ Dynamic: license-file
|
|
|
101
101
|
| **Bangumi** | | ✅ | 💬 条目讨论, 日志, 小组话题 |
|
|
102
102
|
| **今日头条** | ✅ | ✅ | 📰 文章, 微头条 |
|
|
103
103
|
| **Medium** | ✅ | ✅ | 📰 文章 |
|
|
104
|
+
| **煎蛋** | | ✅ | 📰 文章, 💬 话题 |
|
|
104
105
|
|
|
105
106
|
## 📦 安装
|
|
106
107
|
|
|
@@ -26,6 +26,7 @@ src/parsehub/parsers/parser/douban.py
|
|
|
26
26
|
src/parsehub/parsers/parser/douyin.py
|
|
27
27
|
src/parsehub/parsers/parser/facebook.py
|
|
28
28
|
src/parsehub/parsers/parser/instagram.py
|
|
29
|
+
src/parsehub/parsers/parser/jandan.py
|
|
29
30
|
src/parsehub/parsers/parser/kuaishou.py
|
|
30
31
|
src/parsehub/parsers/parser/medium.py
|
|
31
32
|
src/parsehub/parsers/parser/pipix.py
|
|
@@ -50,6 +51,7 @@ src/parsehub/provider_api/coolapk.py
|
|
|
50
51
|
src/parsehub/provider_api/douban.py
|
|
51
52
|
src/parsehub/provider_api/douyin.py
|
|
52
53
|
src/parsehub/provider_api/instagram.py
|
|
54
|
+
src/parsehub/provider_api/jandan.py
|
|
53
55
|
src/parsehub/provider_api/kuaishou.py
|
|
54
56
|
src/parsehub/provider_api/medium.py
|
|
55
57
|
src/parsehub/provider_api/pipix.py
|
|
@@ -259,6 +259,12 @@ class TestPlatformUrlMatching(unittest.TestCase):
|
|
|
259
259
|
"https://www.instagram.com/user.name/reel/C0example/",
|
|
260
260
|
"https://www.instagram.com/reels/DaGI8bPS3ed/",
|
|
261
261
|
],
|
|
262
|
+
Platform.JANDAN: [
|
|
263
|
+
"https://jandan.net/t/6209188",
|
|
264
|
+
"https://jandan.net/t/6209188#comments",
|
|
265
|
+
"https://jandan.net/p/124273",
|
|
266
|
+
"jandan.net/p/124273/",
|
|
267
|
+
],
|
|
262
268
|
Platform.KUAISHOU: [
|
|
263
269
|
"https://www.kuaishou.com/short-video/3xexample",
|
|
264
270
|
"https://v.kuaishou.com/example",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|