from bs4 import BeautifulSouppath = './web/new_index.html'with open(path, 'r') as f: Soup = BeautifulSoup(f.read(), 'lxml') titles = Soup.select('ul > li > div.article-info > h3 > a')for title in titles: print(title.text)输出:Sardinia's top 10 beachesHow to get tannedHow to be an Aussie beach bumSummer's cheat sheet
import bs4 path = './web/new_index.html' with open(path, 'r') as f: Soup = bs4.BeautifulSoup(f.read(), 'lxml') titles = Soup.select('h3 a') for title in titles: print(title.string)