[Python] What is the best way to remove HTML tags in a string using Python?

Discussão em 'Python' iniciado por Stack, Junho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to know what would be the most efficient way to clean all of the HTML tags from this string using python.

    <p>Lorem ipsum dolor sit amet, <strong>consectetur adipiscing
    elit</strong></p>,
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</br>
    <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
    </br>
    <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
    <a href="">Excepteur sint occaecat</a>
    cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>


    I tried using replace('[insert tag]', '') but I have to create multiple replace() lines to remove all of the tags.

    Continue reading...

Compartilhe esta Página