效果展示:
代码如下:
import requests
from bs4 import BeautifulSoup
url = "https://www.gushiwen.org/gushi/chuntian.aspx"
response = requests.get(url)
content = response.text
soup = BeautifulSoup(content, "html.parser")
titles = soup.select(".typecont span a")
with open("chuntian_titles.txt", "w", encoding="utf-8") as file:
for title in titles:
title_text = title.text.strip()
file.write(title_text + "\n")