28 lines
881 B
Python
28 lines
881 B
Python
import re
|
|
|
|
|
|
_BLOCK_TAG_PATTERN = re.compile(r"<(p|div|article|section|img|video|h1|h2|h3|h4|blockquote|li)\b", re.I)
|
|
_HTML_TAG_PATTERN = re.compile(r"<[^>]+>")
|
|
|
|
|
|
def has_publishable_article_content(content: str) -> bool:
|
|
"""判断资讯正文是否达到可发布标准。"""
|
|
raw = (content or "").strip()
|
|
if not raw:
|
|
return False
|
|
|
|
plain = _HTML_TAG_PATTERN.sub("", raw).strip()
|
|
if len(plain) < 50:
|
|
return False
|
|
|
|
# 抓取器和富文本编辑器通常会输出结构化 HTML;纯摘要文本即使较长也先保守视为未完成正文。
|
|
if _BLOCK_TAG_PATTERN.search(raw):
|
|
return True
|
|
|
|
return len(plain) >= 200
|
|
|
|
|
|
def resolve_crawled_article_is_show(content: str) -> int:
|
|
"""根据正文内容决定采集文章的默认状态:1=发布,0=稿子。"""
|
|
return 1 if has_publishable_article_content(content) else 0
|