Skip to content

Commit

Permalink
v1.0.5 update
Browse files Browse the repository at this point in the history
  • Loading branch information
XingzaiUnrivaled committed Dec 19, 2023
1 parent d1654f7 commit 9e3c0e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,21 @@ python3 novel_spider.py
话已至此,本项目仅供爬虫案例参考不要用于非法用途,如果有,与本人和本项目无关。

## 版本更新
* v1.0.4
* 更新了多线程爬虫,默认速度是之前版本的十倍
* 修复了末尾多删一行的bug,可自行调整参数,建议不要太多不然会给封ip
* 修复了在mac上无法创建epub的bug
* 更改了部分异常处理的位置
* 新增输入完id直接帮你查询是什么书籍
* v1.0.3
* 更新路径从原来放到文件等同路径变成了对应了路径,单个txt放入 `./single txt/` 下,依次类推, `./multi txt/`
`./epub/`
* v1.0.2
* 更新部分文本
* 加入进度条,比之前的可视化更好,即使在命令行提示里面也加入书名号,由于加入了进度条需要再安装一个库,如果运行不起来就再跟着readme走一遍。
* v1.0.1
* 修复windows无法写入 `/:*?"<>|\` 这些字符到文件名内的问题,替换成 `丿:星?'《》丨、`

* v1.0.5
1. 新增封面的爬取,现在都有封面了
2. 修复了进度条bug
* v1.0.4
1. 更新了多线程爬虫,默认速度是之前版本的十倍
2. 修复了末尾多删一行的bug,可自行调整参数,建议不要太多不然会给封ip
3. 修复了在mac上无法创建epub的bug
4. 更改了部分异常处理的位置
5. 新增输入完id直接帮你查询是什么书籍
* v1.0.3
1. 更新路径从原来放到文件等同路径变成了对应了路径,单个txt放入 `./single txt/` 下,依次类推, `./multi txt/`
`./epub/`
* v1.0.2
1. 更新部分文本
2. 加入进度条,比之前的可视化更好,即使在命令行提示里面也加入书名号,由于加入了进度条需要再安装一个库,如果运行不起来就再跟着readme走一遍。
* v1.0.1
1. 修复无法写入 `/:*?"<>|\` 这些字符到文件名内的问题,替换成 `丿:星?'《》丨、`
9 changes: 8 additions & 1 deletion novel_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def get_novel(bk_id, write_type=1):
url = param_list["url"]
length = param_list["length"]
author_name = param_list["author_name"]
cover = param_list['cover']

if write_type == 1:
os.makedirs("multi txt", exist_ok=True)
Expand All @@ -71,6 +72,7 @@ def get_novel(bk_id, write_type=1):
book.set_title(novel_name)
book.set_language('zh')
book.add_author(author_name)
book.set_cover(file_name="cover.jpg",content=cover)
spine = store_content(novel_name, url, length, write_type, book=book, thread_count=thread_count_global)
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())
Expand All @@ -88,10 +90,14 @@ def get_book_name(bk_id, print_c=True):
length = len(re.findall("<dd><a href =\"/book/" + str(bk_id) + "/.*</dd>", text))
novel_name = re.findall(">.*</h1>", text)[0][1:-5]
author_name = re.findall("作者[::]\\w*", text)[0][3:]
cover_url = re.findall("src=\"\\S+", re.findall("<img.*>", text)[0])[0][5:-1]
content = requests.get(url=cover_url).content
# with open("1.jpg", 'wb') as f:
# f.write(content)

if print_c:
print(f"本小说为《{novel_name}》,总共有{length}个章节")
return {"url": url, "length": length, "novel_name": novel_name, "author_name": author_name}
return {"url": url, "length": length, "novel_name": novel_name, "author_name": author_name, "cover": content}


# 获得内容与标题
Expand Down Expand Up @@ -133,6 +139,7 @@ def store_content(package_name, url, length, t, book=None, thread_count=10):
j.start()
while flag != thread_count:
time.sleep(5)
tqdm_tqdm.close()
for n in range(1, end):
li = chapters[n]
result = li[0]
Expand Down

0 comments on commit 9e3c0e3

Please sign in to comment.