帮我写一个Python爬虫网络小说的代码
时间: 2023-05-21 15:04:28 浏览: 78
很高兴为您服务。我可以为您提供以下Python爬虫网络小说的代码:import requests
from bs4 import BeautifulSoup# 获取网页
url = 'https://www.example.com/novels'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')# 找到所有小说链接
novel_links = soup.find_all('a', {'class': 'novel_link'})# 遍历所有小说链接
for link in novel_links:
# 获取小说链接
novel_url = link['href']
# 请求小说链接
novel_response = requests.get(novel_url)
# 解析小说内容
novel_soup = BeautifulSoup(novel_response.text, 'lxml')
# 找到小说内容
novel_content = novel_soup.find('div', {'class': 'novel_content'})
# 打印小说内容
print(novel_content.text)
阅读全文