开发时间:20223158:54 importrequestsimportparselimportthreading,osimportqueue classThread(threading。Thread):definit(self,queue,path):threading。Thread。init(self)self。queuequeueself。pathpathifnotos。path。exists(。{}。format(self。path)):os。mkdir(。{}。format(self。path))defrun(self)None:whileTrue:urlself。queue。get()try:downloadnovel(url,self。path)except:print(下载失败)finally:self。queue。taskdone() defdownloadnovel(url,path):resgetresponse(url)selctorparsel。Selector(res)titleselctor。css(。booknameh1::text)。get()print(title)content。join(selctor。css(content::text)。getall())使用join方法改变内容;withopen(pathtitle。txt,w,encodingutf8)asf:f。write(content)print(title,保存成功!)f。close() defgetresponse(url):获得网站源码;responserequests。get(url)response。encodingutf8returnresponse。text ifnamemain:函数入口urlstr(input(请输入你要下载小说的url:))responsegetresponse(url)selparsel。Selector(response)novelnamesel。css(infoh1::text)。get()urllistsel。css(。boxconpdldda::attr(href))。getall()queuequeue。Queue()path。{}。format(novelname)forurl1inurllist:urlhttps:www。xbiquge。laurl1queue。put(url)forxinrange(10):workThread(queue,path)work。daemonTruework。start()queue。join()print(下载完毕。。。)