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)

你可能感兴趣的:(爬虫,人工智能,python)