1
我想提取新聞頁面的最多讀取部分中的標題。這是我到目前爲止,但我得到的所有標題。我只是想要閱讀最多的部分。用BS4提取大多數讀取標題
`
import requests
from bs4 import BeautifulSoup
base_url = 'https://www.michigandaily.com/section/opinion'
r = requests.get(base_url)
soup = BeautifulSoup(r.text, "html5lib")
for story_heading in soup.find_all(class_= "views-field views-field-title"):
if story_heading.a:
print(story_heading.a.text.replace("\n", " ").strip())
else:
print(story_heading.contents[0].strip())`