11 lines
342 B
Python
11 lines
342 B
Python
from bs4 import BeautifulSoup
|
|
|
|
with open("html_files/卷001之1.html", "r", encoding="utf-8") as f:
|
|
soup = BeautifulSoup(f.read(), "html.parser")
|
|
|
|
poem_div = soup.find("div", class_="poem")
|
|
if poem_div:
|
|
for i, p in enumerate(poem_div.find_all("p")[:20]):
|
|
print(f"--- P {i} ---")
|
|
print(p.text[:100].replace('\n', ' '))
|