How do I fix wrongly nested / unclosed HTML tags?

前端 未结 5 1234
悲&欢浪女
悲&欢浪女 2020-12-01 09:56

I need to sanitize HTML submitted by the user by closing any open tags with correct nesting order. I have been looking for an algorithm or Python code to do this but haven\'

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 10:01

    I tried to use, below method but Failed on python 3

    from BeautifulSoup import BeautifulSoup
    soup = BeautifulSoup(page, 'html5lib')
    

    I tried below and got Success

    soup = bs4.BeautifulSoup(html, 'html5lib')
    f_html = soup.prettify()
    print(f'Formatted html::: {f_html}')
    

提交回复
热议问题