How to convert HTML object to str object

Generally, str objects display on the console. How can I convert my html object to an str object so that it can display on the console?

x = HTML('<p>hello</p>')
string = str(x)
display(string)

  • 1

    try using html2text script ; import html2text html_content = ‘<p>hello</p>’ text_content = html2text.html2text(html_content) print(text_content)

    – 

  • @Sumanjha if you’re going to provide full code, please write an answer, not a comment.

    – 




  • 1

    What is HTML in this case? (which package are you importing?)

    – 

  • I am importing from pyscript import HTML . @Suman jha your code works for me but displays few blank spaces after display.

    – 

Leave a Comment