接着昨天的程序,加入新研究的搜索小说名获得章节链接,直接爬功能
from lxml import etree
import requests
from threading import Thread,enumerate
import os
from time import sleep,time
import execjs
import urllib.parse
import json
def inner(name,i,begin,end,cwd):
f = open(f"{cwd}downloads/{name}/{i}.txt", mode='w+', encoding='utf-8')
for link in novel_list[begin:end]:
inter(link, f,i)
if link == novel_list[end - 1]:
print(f"\n线程{i}执行完毕")
print(f"\n剩余线程数量{len(enumerate())}")
base_xc = 2 if not cwd else 4
if len(enumerate()) <= base_xc:
print(enumerate())
print("\n全本下载完毕")
t2 = time()
print(f"\n本次下载小说总共耗时{round(t2 - t1)}s")
hebing(f"{cwd}downloads/{name}")
f.close()
for i in range(1,xc_num+1):
begin = 20*(i-1)
end = 20*i if i != xc_num else article_num
if i == xc_num:
print(f"\n全部线程开启完毕")
thread_it(inner,name,i,begin,end,cwd)
sleep(0.5)