Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
feat: 批量模式新增支持手机链接/ID
Browse files Browse the repository at this point in the history
  • Loading branch information
shing-yu committed Feb 7, 2024
1 parent e291760 commit d2b6486
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
36 changes: 30 additions & 6 deletions src/fanqie_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

# 导入必要的模块
import os
import re
import time
import datetime
from tqdm import tqdm
Expand Down Expand Up @@ -49,11 +50,34 @@ def fanqie_b(encoding, user_agent, path_choice, data_folder):
print("urls.txt文件为空")
return
else:
# 检查每行是否包含"/page/",并且不是空行
for line in lines:
# 检查每行格式,并且不是空行
urls = []
for i, line in enumerate(lines, start=1):
line = line.strip()
if line and "/page/" not in line:
print(f"语法错误:第{line}行")
# if line and "/page/" not in line:
# print(f"语法错误:第{line}行")
# return "file syntax is incorrect"
try:
if line is False:
continue
# 如果是空行,则跳过
elif line.isdigit():
book_id = line
urls.append(f"https://fanqienovel.com/page/{book_id}")
break
elif "fanqienovel.com/page/" in line:
book_id = re.search(r"fanqienovel.com/page/(\d+)", line).group(1)
urls.append(f"https://fanqienovel.com/page/{book_id}")
break # 如果是正确的链接,则退出循环
elif "changdunovel.com" in line:
book_id = re.search(r"book_id=(\d+)&", line).group(1)
urls.append(f"https://fanqienovel.com/page/{book_id}")
break
else:
print(Fore.YELLOW + Style.BRIGHT + f"无法识别的内容:第{i}\n内容:{line}")
return "file syntax is incorrect"
except TypeError:
print(Fore.YELLOW + Style.BRIGHT + f"链接无法识别:第{i}\n内容:{line}")
return "file syntax is incorrect"

print("urls.txt文件内容符合要求")
Expand Down Expand Up @@ -85,14 +109,14 @@ def fanqie_b(encoding, user_agent, path_choice, data_folder):
break

# 对于文件中的每个url,执行函数
for url in lines:
for url in urls:
url = url.strip() # 移除行尾的换行符
if url: # 如果url不为空(即,跳过空行)
download_novels(url, encoding, user_agent, path_choice, folder_path, data_folder)
time.sleep(1)

except Exception as e:
print(f"发生错误:{str(e)}")
print(Fore.RED + Style.BRIGHT + f"发生错误:{str(e)}")
return f"发生错误:{str(e)}"


Expand Down
4 changes: 2 additions & 2 deletions src/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ def get_parameter(retry):
pass
if retry is True:
print("您在urls.txt中输入的内容有误,请重新输入")
print("请重新在程序同文件夹(或执行目录)下的urls.txt中,以每行一个的形式写入目录页链接")
print("请重新在程序同文件夹(或执行目录)下的urls.txt中,以每行一个的形式写入链接/ID")
elif retry is False:
print("请在程序同文件夹(或执行目录)下的urls.txt中,以每行一个的形式写入目录页链接")
print("请在程序同文件夹(或执行目录)下的urls.txt中,以每行一个的形式写入链接/ID")
input("完成后请按Enter键继续:")
else:
# 不是则让用户输入小说目录页的链接
Expand Down

0 comments on commit d2b6486

Please sign in to comment.