笔趣阁在线小说阅读网站

大家好,感谢邀请,今天来为大家分享一下笔趣阁在线小说阅读网站的问题,以及和python学习分享:笔趣阁小说全本下载工具爬虫源码的一些困惑,大家要是还不太明白的话,也没有关系,因为接下来将为大家分享,希望可以帮助到大家,解决大家的问题,下面就开始吧!

#导入模块nimportrequestsnimportparselnfromlxmlimportetreenimportrenimportpandasaspdnimportdatetimenimporttimenfromtqdmimporttqdmnimportprettytableasptn#请求头nheaders={'User-Agent':'Mozilla/5.0(WindowsNT6.1;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/78.0.3904.108Safari/537.36'}ncurr_time=datetime.datetime.now()ntimes=datetime.datetime.strftime(curr_time,'%Y-%m-%d%H:%M:%S')nprint(f'现在是:{times}by琴棋书画')nprint()nprint('***********欢迎使用笔趣阁小说全本下载工具*************')nprint()nwhileTrue:n#请求数据nkeyword=input('请输入你想要搜索的小说名字(0退出):')nifkeyword=='0':nbreaknseacher_url=f'https://www.biquge9.com/s?q={keyword}'nrespones=requests.get(seacher_url,headers=headers)n#print(respones.text)n#解析获取数据nselector=etree.HTML(respones.text)nxs_urls=selector.xpath('//h4/a[contains(@href,"/book/")]/@href')#获取小说地址列表nxs_names=selector.xpath('//a[contains(@href,"/book/")]/text()')#获取小说名字列表nxs_authers=selector.xpath('//div[contains(@class,"author")]/text()')#获取小说作者列表n#selector=parsel.Selector(respones.text)n#xs_urls=selector.css('.bookinfo.booknamea::attr(href)').getall()n#xs_names=selector.css('bookinfo.booknamea::text').getall()n#xs_authers=selector.css('.bookinfodiv::text').getall()n#print(xs_authers,xs_names,xs_urls)ntb=pt.PrettyTable()ntb.field_names=['序号','书名','作者','小说ID']nnum=0nifxs_names:n#print(xs_urls,xs_names,xs_authers)nxs_list=[]n#遍历弄表nforxs_url,xs_name,xs_autherinzip(xs_urls,xs_names,xs_authers):nxs_id=xs_url.split('/')[2]#小说IDnxs_url='https://www.biquge9.com'+xs_url#小说网址nxs_name=xs_name.strip()#小说书名nxs_auther=xs_auther.split(':')[1]#小说作者n#print(xs_id,xs_url,xs_name,xs_auther)ndict={'书名':xs_name,'作者':xs_auther,'ID':xs_id}#生成字典nxs_list.append(dict)#小说信息列表ntb.add_row([num,xs_name,xs_auther,xs_id])nnum=num+1nprint(tb)n#print()nprint(f'一共搜索到{len(xs_list)}条数据')nprint()n#sea_data=pd.DataFrame(xs_list)n#print(sea_data)#输出小说信息列表nnprint()nkey_num=input('请输入你要下载的小说序号:')nprint()nprint('小说正在下载,已完成......')nxs_ID=xs_list[int(key_num)]['ID']nurl='https://www.biquge9.com/book/'+xs_IDnurls=[url+'/{}.html'.format(str(i))foriinrange(1,5000)]#生成章节地址列表n#print(urls)nnforurl1intqdm(urls):#遍历章节地址列表ndata_1=requests.get(url1,headers=headers)#请求章节文本nselector=parsel.Selector(data_1.text)n#print(selector)ntitle=selector.css('.contenth1::text').get()#获取章节标题n#print(title)ncontent=selector.css('#chaptercontent::text').getall()#获取章节正文n#print(content)ncontent_1='\n'.join(content)n#print(content_1)nwithopen(xs_name+'.txt','a+',encoding='utf-8')asfile:#保存小说内容到TXT文件niftitle!='':nfile.write(title)nfile.write('\n')nfile.write(content_1)nfile.write('\n')n#print('正在保存',title)nnelse:nfile.write(content_1)nfile.write('\n')nelse:nprint('请正确输入小说名字或作者名字,没有查到这本书的数据.....')

关于本次笔趣阁在线小说阅读网站和python学习分享:笔趣阁小说全本下载工具爬虫源码的问题分享到这里就结束了,如果解决了您的问题,我们非常高兴。