无法使用 Beautiful Soup 来废弃“<div class="tdb-block-inner td-fix-index">”

问题描述 投票:0回答:1

我正在尝试使用 BeautiFul soup 废弃一个网站并获取下面的文本,但无法获取此标题下的内容

a = 'https://insights.blackcoffer.com/how-will-covid-19-affect-the-world-of-work-2/'
response = requests.get(a)
soup = BeautifulSoup(response.content,'html.parser')
article_content = soup.find('div', class_="tdb-block-inner td-fix-index")
python html web-scraping beautifulsoup
1个回答
0
投票

您可以使用 CSS 选择器

.td-post-content
来获取文章内容:

import requests
from bs4 import BeautifulSoup

a = "https://insights.blackcoffer.com/how-will-covid-19-affect-the-world-of-work-2/"
response = requests.get(a)
soup = BeautifulSoup(response.content, "html.parser")


article_content = soup.select_one(".td-post-content")
print(article_content.text)

打印:

As business close to help prevent transmission of COVID-19, financial concerns and job losses are one of the first human impacts of the virus;
Not knowing how this pandemic will play out also affects our economic, physical and mental well-being;Despite this fear, businesses and communities in many regions have shown a more altruistic response in the face of crisis – actions which could help countries preparing for COVID-19.

...
© www.soinside.com 2019 - 2024. All rights reserved.