借助html.escape()
方法,我們可以通過以下方式將html腳本轉換為字符串:使用html.escape()
方法。
用法: html.escape(String)
返回:從html返回一個ascii字符腳本字符串。
範例1:
在這個例子中,我們可以通過使用html.escape()
方法,我們可以使用此方法將html腳本轉換為ascii字符串。
# 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)
輸出:
<html><head></head><body><h1>This is python</h1></body></html>
範例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)
輸出:
<html><head></head><body><h1>GeeksForGeeks</h1></body></html>
相關用法
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 html.escape() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。