[Python] How to get a string form of BeautifulSoup NavigableString that keeps the tags

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

  1. Stack

    Stack Membro Participativo

    I'm processing a large data file in HTML format using Python's BeautifulSoup.

    And I'm getting NavigableStrings which I need to unicode encode before printing out. If I take either the get_text() or .string from the NavigableString, it seems to strip out all the HTML tags from it.

    On the other hand, NavigableString itself doesn't seem to have a .encode("utf-8") type option.

    So how can I turn my NavigableString into an ordinary string without stripping the tags?

    Continue reading...

Compartilhe esta Página