1
ニュースページの[Most Read]セクションでタイトルを抽出します。これはこれまで私が持っていたものですが、私はすべてのタイトルを手に入れています。私はちょうど最も読み込みセクションにそれらをしたい。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())`