<div class="bookMl"><strong>卷一·上焦篇</strong></div>
<div style=" clear:both; overflow:hidden; height:auto;">
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4FB26CC490CA53BD64.aspx">序</a></span>
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4F8AD41D06CFD8C8C6.aspx">原病篇</a></span>
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4F8F3A8474F1C283B5.aspx">风温、温热、温疫、温</a></span>
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4F0D406BBBD3795F62.aspx">暑温</a></span>
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4FB806330877EE2459.aspx">伏暑</a></span>
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4FDD4DA0A5ACF2A66F.aspx">湿温、寒湿</a></span>
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4F3E0A97159149E65A.aspx">温疟</a></span>
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4FC46098CBC139BFC1.aspx">秋燥</a></span>
<span><a href="https://so.gushiwen.cn/guwen/bookv_46653FD803893E4F3DA65DC503838A79.aspx">补秋燥胜气论</a></span>
</div>
python 的 爬虫工具
import requests
from bs4 import BeautifulSoup
url = 'https://so.gushiwen.cn/guwen/bookv_46653FD803893E4FB26CC490CA53BD64.aspx'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
link_list = []
for link in soup.find_all('a'):
href = link.get('href')
if href:
link_list.append(href)
with open('links.txt', 'w') as f:
for link in link_list:
f.write(link + '\n')
for link in link_list:
url = link.strip() # 去除链接中的空格和换行符
response = requests.get(url)
file_name = url.split('/')[-1] # 从链接中提取文件名
with open(file_name, 'wb') as f:
f.write(response.content)
在此代码中,爬虫部分和批量下载部分分别在两个不同的for循环中实现,因此可以先爬取链接并保存到文本文件中,然后再使用另一个for循环进行批量下载。