如何在python中制作標簽查找器?
我的標記代碼
<h1>hello
<p>world
<b>from
<li>python
如何找出python中標記代碼中使用的所有標簽,輸出應該像
['h1', 'p', 'b', 'li']
有沒有辦法在python中找到標簽
如果有任何錯誤,任何人都可以解決它
uj5u.com熱心網友回復:
您可以使用re.findall:
import re
s = """<h1>hello
<p>world
<b>from
<li>python"""
tags = re.findall(r"<(.*?)>", s)
print(tags) # ['h1', 'p', 'b', 'li']
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/337992.html
標籤:Python
上一篇:即使在類屬性中滿足要求,也會引發AssertionError?
下一篇:基于列的Numpy過濾矩陣
