# https://url/kan/45458/1.html import time from asyncio import threads # 1.单章节下载url.bq02.cc # 2.数据解析(静态数据 xpath re正则 bs4 css) from bs4 import BeautifulSoup # # 请求url 数据类型 字符串 import threading import requests from bs4 import BeautifulSoup def getbook(i): # 这是有20个活 # for i in range(1,21): book_url = requests.get(f"url/{i}.html") headers = { 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36' } # 静态提取页面数据 动态用点json # respuest = requests.get(url = book_url.url,headers=headers).text respuest = requests.get(url=book_url.url).text # 数据解析 bs4解析 soup = BeautifulSoup(respuest, 'html.parser') # div_element = soup.find('div', attrs={'class': 'kan'}) div_element = (soup.find('div',id='标签:headers,python,url,bs4,import,div,小说,requests,下载 From: https://blog.csdn.net/qq_30863945/article/details/145192622