Ваш код работает нормально. Это просто не дает результатов для politics
страницы.
Попробуйте:
import requests
from bs4 import BeautifulSoup
url='https://edition.cnn.com/'
topics = ['world','politics','business']
headlines = []
for topic in topics:
r = requests.get(url+topic)
soup=BeautifulSoup(r.content,'html.parser')
for span in soup.find_all('span',{'class':"cd__headline-text"}):
headlines.append(span.text)
print(span.text)
print()
headlines
распечатывает на:
The bizarre ways that coronavirus is changing etiquette
Over half of all virus cases in one country are linked to this group
Trump's Middle East plan could jeopardize Jordan-Israel peace treaty, Jordan PM says
Irish duo's win marks rare victory for women in the 'Nobel of architecture'
After more than 240 days, Australia's New South Wales is finally free from bushfires
Child drowns off Greek coast after Turkey opens border with Europe
A migration crisis and disagreement with Turkey is the last thing Europe needs right now
Vatican to open controversial WW2-era files on Pope Pius XII
Netanyahu projected to win Israeli election, but exit polls suggest bloc just short of majority
Adviser to Iran's Supreme Leader dies after contracting coronavirus
Israeli election exit polls project Netanyahu in lead
She became pregnant at the age of 12. Now, Kenya's Christine Ongare is an Olympic boxing qualifier
Nigeria says it is ready and more than capable of dealing with coronavirus
Kenya bans commercial slaughter of donkeys following a rise in animal theft
Violence forces Haiti to cancel Carnival
....
Вы надеваете не получают результаты для politics
, потому что содержимое отображается динамически с Javascript в браузере (как объяснил Дж. Андерсон в его комментариях). С requests
однако вы получите только сырой HTML.
Откройте сайт в браузере и сравните View page source
с Inspect element
. Первый дает необработанный HTML, второй - обработанный HTML.