Python3爬虫小说章节内容

import requests
from bs4 import BeautifulSoup
import txtread

url = ‘https://www.biqukan.com/0_790/’

responce = requests.get(url)
responce.encoding = ‘gbk’
html = responce.text
soup = BeautifulSoup(html, ‘lxml’)
#print(soup)

#获取标题名字
title = soup.find_all(‘dt’)
title_text = title[1].string[:-3]
print(title_text)

#获取章节链接和章节名 在 'a’标签的列表里面分析
CharAll = soup.find_all(‘div’,class_=‘listmain’)
#print(type(CharAll))
#print(CharAll[0])
HrefList = BeautifulSoup(str(CharAll[0]), ‘lxml’)
Server = ‘https://www.biqukan.com’
for each in HrefList.find_all(‘a’)[12:]:
href = Server + each.get(‘href’)
CharName = each.string
txtChar = txtread.CharTxt(href)
print(CharName, href)
print(txtChar)

发布了6 篇原创文章 · 获赞 1 · 访问量 346

猜你喜欢

转载自blog.csdn.net/weixin_44600471/article/details/100791052
今日推荐