Skip to content

Commit a48ff3e

Browse files
authored
Merge pull request #5 from God-2077/dev
[novel_crawler] 更新小说爬虫版本至 v.25.07.06,增强输出功能,新增对 br 标签的处理逻辑,优化配置文件,修复若干问题
2 parents 4450dba + 78661e0 commit a48ff3e

4 files changed

Lines changed: 854 additions & 10 deletions

File tree

novel_crawler/README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
爬取小说章节内容页面, 保存到本地
88
最后去阅读小说了
99

10-
最新版:[novel_crawler_v.25.06.05.py][5]
10+
最新版:[novel_crawler_v.25.07.06][6]
1111

1212
## 说明
1313

@@ -77,7 +77,7 @@ rules:
7777
novel_chapter_content_div: 'div.content'
7878

7979
# 小说单段规则(相对于小说章节内容区域)
80-
novel_chapter_content_p: 'p' # 可以是 p, div, span 等
80+
novel_chapter_content_p: 'p' # 可以是 br, p, div, span 等
8181

8282
# 小说净化内容配置
8383
purify:
@@ -121,6 +121,12 @@ python ***.py config.yml
121121

122122
## 日志
123123

124+
- [novel_crawler_v.25.07.06][6]
125+
- 使用 rich 库增强输出
126+
- 增加对 br 标签的特殊处理逻辑
127+
- 排除目录 JS 链接
128+
- 若干优化
129+
124130
- [novel_crawler_v.25.06.05.py][5]
125131
- 更新 epub 章节渲染模板
126132

@@ -139,8 +145,15 @@ python ***.py config.yml
139145
- [novel_crawler_v.24.12.01.py][2]
140146
- 第一个版本
141147

142-
[1]: https://github.com/God-2077/python-code/tree/main/novel_crawler/novel_crawler_v.24.12.01.py
143-
[2]: https://github.com/God-2077/python-code/tree/main/ftp_server/novel_crawler/novel_crawler_v.24.12.01.py
144-
[3]: https://github.com/God-2077/python-code/tree/main/ftp_server/novel_crawler/novel_crawler_v.25.02.03.py
145-
[4]: https://github.com/God-2077/python-code/tree/main/ftp_server/novel_crawler/novel_crawler_v.25.06.02.py
146-
[5]: https://github.com/God-2077/python-code/tree/main/ftp_server/novel_crawler/novel_crawler_v.25.06.05.py
148+
<!-- [1]: novel_crawler_v.24.12.01.py
149+
[2]: novel_crawler_v.24.12.01.py
150+
[3]: novel_crawler_v.25.02.03.py
151+
[4]: novel_crawler_v.25.06.02.py
152+
[5]: novel_crawler_v.25.06.05.py
153+
[5]: novel_crawler_v.25.06.05.py -->
154+
[1]: novel_crawler_v.24.12.01.py
155+
[2]: novel_crawler_v.24.12.01.py
156+
[3]: novel_crawler_v.25.02.03.py
157+
[4]: novel_crawler_v.25.06.02.py
158+
[5]: novel_crawler_v.25.06.05.py
159+
[6]: novel_crawler_v.25.07.06.py

novel_crawler/config.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# 小说爬虫配置(示例)
2+
# 使用方式: python text.py config.yml
3+
4+
# 基本配置
5+
basic:
6+
# 小说详情页面的 URL
7+
novel_detail_url: 'https://www.31ec1.lol/read/45159/'
8+
9+
# 小说章节列表页面的 URL 列表
10+
# 如果章节列表在小说详情页面,可以直接使用 novel_detail_url
11+
novel_chapter_url:
12+
- 'https://www.31ec1.lol/read/45159/'
13+
14+
# 小说保存路径,默认为当前目录
15+
download_path: './downloads'
16+
17+
# 小说文件的编码(TXT) (utf-8, gbk, gb2312等)
18+
novel_file_encoding: 'utf-8'
19+
20+
# 输出格式 (txt, epub)
21+
output_format: 'txt'
22+
23+
# 缩进字符串
24+
indent_string: ' '
25+
26+
# 是否启用调试模式
27+
debug: True
28+
29+
# 选择器规则配置
30+
rules:
31+
# 小说名称 CSS 选择器
32+
novel_name: 'body > div.book > div.info > h1'
33+
34+
# 小说作者 CSS 选择器
35+
novel_author: 'body > div.book > div.info > div.small > span:nth-child(1)'
36+
37+
# 小说简介 CSS 选择器
38+
novel_intro: 'body > div.book > div.info > div.intro > dl > dd'
39+
40+
# 小说章节区域 CSS 选择器
41+
novel_chapter_div: 'body > div.listmain'
42+
43+
# 小说单个章节的区域(相对于小说章节区域)
44+
novel_chapter_div_only: 'dd'
45+
46+
# 小说章节名称(相对于小说章节区域)
47+
novel_chapter_name: 'a'
48+
49+
# 小说章节 URL(相对于小说章节区域)
50+
novel_chapter_url: 'a'
51+
52+
# 小说章节内容区域 CSS 选择器
53+
novel_chapter_content_div: '#chaptercontent'
54+
55+
# 小说单段规则(相对于小说章节内容区域)
56+
novel_chapter_content_p: 'br' # 可以是 p, div, span 等
57+
58+
# 小说净化内容配置
59+
purify:
60+
# 需要净化的文本列表
61+
text:
62+
- '广告内容1'
63+
- '广告内容2'
64+
65+
# 需要净化的正则表达式列表
66+
re:
67+
- '[\d]{4}-[\d]{2}-[\d]{2}' # 去除日期格式
68+
- '本章节.*更新' # 去除更新提示
69+
70+
# 网络请求配置
71+
network:
72+
# 请求头设置
73+
headers:
74+
User-Agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
75+
Referer: 'https://www.31ec1.lol/'
76+
Accept-Language: 'zh-CN,zh;q=0.9'
77+
78+
# Cookies 设置
79+
cookies:
80+
# session_id: 'abc123'
81+
# token: 'xyz456'
82+
83+
# 请求超时时间(秒)
84+
timeout: 5
85+
86+
# 失败重试次数
87+
max_retries: 5
88+
89+
# 请求间隔时间(毫秒)
90+
request_interval_ms: 0

0 commit comments

Comments
 (0)