0

У тега 'p' есть дочерний тег 'strong', как его удалить из выдачи?

soup = BeautifulSoup(r.text , "html.parser")

import re

for tag in soup.find_all(re.compile('^p'):

print(tag)

1 ответ 1

0

Попробуйте что-то вроде этого. Здесь используется метод extract(), который позволяет удалять теги.

from bs4 import BeautifulSoup
import re

# Ваш r.text
# ...

soup = BeautifulSoup(r.text, 'html.parser')

for tag in soup.find_all(re.compile('^p')):
    strong_tag = tag.find('strong')
    if strong_tag:
        strong_tag.extract()

print(tag)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.