最近看动漫,斗破苍穹,有点痴迷,动漫看完了,开始搜小说看,一般得小说网站都有广告啥的,我找了个还不错得网站。(斗破小说才看完,下面已大主宰为例)
脚本可实现:在pycharm里去一章一章读取,在控制台输出(方便你摸鱼,别人以为你在调试代码)
需要改的参数
对应上图信息
初次运行:输入页数
显示如下:程序会一直运行,输入u 上一章,n/其他字母,下一章
[Python] 纯文本查看 复制代码 # -*- coding:utf-8 -*-
from urllib.parse import urljoin
import requests
from scrapy import Selector
def get_info(url):
response = requests.get(url)
response.encoding = response.apparent_encoding
content = Selector(text=response.text).css('#content').get()
upage = Selector(text=response.text).xpath('//*[text()="上一章"]/@href').extract_first()
nextpage = Selector(text=response.text).xpath('//*[text()="下一章"]/@href').extract_first()
print(content)
return upage, nextpage
def get_page(url):
u, n = get_info(url)
u = urljoin(url, u)
n = urljoin(url, n)
print(f'本章:{url.split("/")[-1].split(".")[0]}')
# print(f'上一章:{u},下一章:{n}')
while True:
url = input('输入u/n:')
if url == 'u':
url = u
else:
url = n
get_page(url)
if __name__ == '__main__':
page = input('输入页数:')
url = f'https://www.doupobook.com/dazhuzai/{page}.html'
get_page(url)
|