Skip to content
Related Articles

Related Articles

Improve Article

html.escape() in Python

  • Last Updated : 22 Apr, 2020

With the help of html.escape() method, we can convert the html script into a string by replacing special characters with the string with ascii characters by using html.escape() method.

Syntax : html.escape(String)

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Return : Return a string of ascii character script from html.



Example #1 :
In this example we can see that by using html.escape() method, we are able to convert the html script to ascii string by using this method.




# import html
import html
  
s = '<html><head></head><body><h1>This is python</h1></body></html>'
# Using html.escape() method
gfg = html.escape(s)
  
print(gfg)

Output :

<html><head></head><body><h1>This is python</h1></body></html>

Example #2 :




# import html
import html
  
s = '<html><head></head><body><h1>GeeksForGeeks</h1></body></html>'
# Using html.escape() method
gfg = html.escape(s)
  
print(gfg)

Output :

<html><head></head><body><h1>GeeksForGeeks</h1></body></html>

My Personal Notes arrow_drop_up
Recommended Articles
Page :