我正在尝试解析一个网站。我正在使用 beaitufulsoup4 库。在 span 标签内,我需要获取除 br 标签之外的所有 b 标签及其内容。如果使用 .text 方法,则 br 标记后面的文本将被删除。如何才能做到这一点?
站点布局:
我的代码:
def get_data():
page = requests.get("https://www.forbes.ru/milliardery/487053-10-bogatejsih-ludej-mira-2023-rejting-forbes")
soup = BeautifulSoup(page.text, "lxml")
all_person = soup.find_all('figcaption', class_='EXdHT')
for person in all_person:
name = person.find('h2', class_='jYzxi').text
about_person = person.find('div', class_='CFaZ3').find('p').find('span')
print(about_person)
get_data()









