webpage-parser 0.1.0__py3-none-any.whl
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.
- webpage_parser/__init__.py +11 -0
- webpage_parser/author.py +503 -0
- webpage_parser/content.py +915 -0
- webpage_parser/extract.py +63 -0
- webpage_parser/htmlprep.py +760 -0
- webpage_parser/pagegate.py +177 -0
- webpage_parser/pipeline.py +196 -0
- webpage_parser/pubtime.py +490 -0
- webpage_parser/siteconfig.py +110 -0
- webpage_parser/sitespecific.py +170 -0
- webpage_parser/timetext.py +365 -0
- webpage_parser/title.py +222 -0
- webpage_parser/util.py +95 -0
- webpage_parser-0.1.0.dist-info/METADATA +93 -0
- webpage_parser-0.1.0.dist-info/RECORD +18 -0
- webpage_parser-0.1.0.dist-info/WHEEL +5 -0
- webpage_parser-0.1.0.dist-info/entry_points.txt +2 -0
- webpage_parser-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""CLI 入口:python3 system/extract.py --input <rows.jsonl> --output <preds.jsonl>
|
|
2
|
+
|
|
3
|
+
契约:
|
|
4
|
+
- 输出行数与顺序严格对齐输入
|
|
5
|
+
- 每行 JSON 对象至少含 title/content/pub_time/author 四个字符串键
|
|
6
|
+
- 单行异常吞掉并降级为空值;进程退出码恒为 0
|
|
7
|
+
- 无网络访问;流式读写,绝不整体加载
|
|
8
|
+
"""
|
|
9
|
+
import argparse
|
|
10
|
+
import json
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from .pipeline import process_row, empty_result
|
|
15
|
+
except ImportError:
|
|
16
|
+
sys.path.insert(0, __file__.rsplit("/", 1)[0])
|
|
17
|
+
from pipeline import process_row, empty_result
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _safe_row(line):
|
|
21
|
+
try:
|
|
22
|
+
obj = json.loads(line)
|
|
23
|
+
return obj if isinstance(obj, dict) else None
|
|
24
|
+
except Exception:
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def main():
|
|
29
|
+
ap = argparse.ArgumentParser()
|
|
30
|
+
ap.add_argument("--input", required=True)
|
|
31
|
+
ap.add_argument("--output", required=True)
|
|
32
|
+
args = ap.parse_args()
|
|
33
|
+
|
|
34
|
+
with open(args.input, "r", encoding="utf-8", errors="replace") as fin, \
|
|
35
|
+
open(args.output, "w", encoding="utf-8") as fout:
|
|
36
|
+
for line in fin:
|
|
37
|
+
if not line.strip():
|
|
38
|
+
continue
|
|
39
|
+
row = _safe_row(line)
|
|
40
|
+
try:
|
|
41
|
+
if row is None:
|
|
42
|
+
res = empty_result()
|
|
43
|
+
else:
|
|
44
|
+
res = process_row(row)
|
|
45
|
+
except Exception:
|
|
46
|
+
res = empty_result()
|
|
47
|
+
for k in ("title", "content", "pub_time", "author"):
|
|
48
|
+
v = res.get(k)
|
|
49
|
+
if not isinstance(v, str):
|
|
50
|
+
res[k] = "" if v is None else str(v)
|
|
51
|
+
try:
|
|
52
|
+
fout.write(json.dumps(res, ensure_ascii=False) + "\n")
|
|
53
|
+
except Exception:
|
|
54
|
+
fout.write(json.dumps(empty_result(), ensure_ascii=False) + "\n")
|
|
55
|
+
return 0
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
try:
|
|
60
|
+
main()
|
|
61
|
+
except Exception:
|
|
62
|
+
pass
|
|
63
|
+
sys.exit(0)
|