[Python] 纯文本查看 复制代码import requests
from bs4 import BeautifulSoup
import lxml
import re
#爬取天籁小说网小说
#url = 'https://www.23txt.com/files/article/html/60/60792/'
url = input('网址URL:\n本脚本仅支持天籁小说 \n类型:https://www.23txt.com/files/article/html/**/*****/ \n')
url_fix = input('类型:**/******/ \n')
req = requests.get (url)
req.encoding = 'GBK'
text = req.text
bf = BeautifulSoup (text,'lxml')
title = bf.find_all('div',id = 'info')
title = bf.find_all('h1')
title = title[0].text.replace ('h1',' ')
text_info = re.findall(r'
text_info_list = re.findall (r'
(.*?)'% url_fix ,text_info)for book in text_info_list:
text_url = book[0]
text_name = book[1]
text_download = url + text_url
reqs = requests.get(text_download)
reqs.encoding = 'GBK'
texts = reqs.text
texts_info = re.findall(r'
texts_info = texts_info.replace (' ',' ')
texts_info = texts_info.replace (';',' \n')
texts_info = texts_info.replace ('
',' ')
with open ('%s.txt'% title,'a+',encoding = 'GBK')as f:
f.write ('\n\n')
f.write (text_name)
f.write (texts_info)
f.write ('\n')
print (text_name)
print ('下载完成')