Используйте .find_all()
вместо .select()
для выбора элементов для разложения. .select()
используется только с селекторами CSS:
for remove1 in soup.find_all("figure", attrs={"class": "element-atom"}):
remove1.decompose()
for remove2 in soup.find_all("aside", attrs={"data-component": "rich-link"}):
remove2.decompose()
for remove3 in soup.find_all("div", attrs={"class": "submeta"}):
remove3.decompose()
textHeadline = soup.find("h1", attrs={"class": "content__headline"})
textUnderline = soup.find("div", attrs={"class": "tonal__standfirst"})
textBody = soup.find("div", attrs={"class": "content__article-body from-content-api js-article__body"})
# Final text
reductionResult = str(textHeadline) + str(textUnderline) + str(textBody)
print(reductionResult)
Отпечатки:
<h1 class="content__headline" itemprop="headline">
'Clear discrimination': South Sudanese react to exclusion from migration program
</h1><div class="tonal__standfirst u-cf">
...and so on.