gpt4 book ai didi

python - 在哪里可以找到 Python 中所有可能的 HTML 标签的列表?

转载 作者:太空宇宙 更新时间:2023-11-04 09:21:06 25 4
gpt4 key购买 nike

Python 中是否有一个列出所有 HTML 标签的标准模块?

例如,我想做这样的事情:

if is_valid_html_tag('div'):
print 'div is a valid tag'

if is_not_valid_html_tag('boda'):
print 'boda is not a valid tag'

为此,我需要一个 Python 中所有标签的列表。我想知道是否有人已经组装了它们,或者可能包含在 Python 库中的 xml 或其他 html 模块中?

谢谢,Boda Cydo。

最佳答案

我不知道是否有一个内置模块可以做到这一点。我建议找到标签列表,然后编写这样的函数...

def is_valid_html_tag(tag_name):  
tags=["a","abbr","acronym","address","area","b","base","bdo","big","blockquote","body","br","button","caption","cite","code","col","colgroup","dd","del","dfn","div","dl","DOCTYPE","dt","em","fieldset","form","h1","h2","h3","h4","h5","h6","head","html","hr","i","img","input","ins","kbd","label","legend","li","link","map","meta","noscript","object","ol","optgroup","option","p","param","pre","q","samp","script","select","small","span","strong","style","sub","sup","table","tbody","td","textarea","tfoot","th","thead","title","tr","tt","ul","var"]
return tag_name in tags

我认为有效标签列表取决于您的文档类型。这些来自http://htmldog.com/reference/htmltags/ .他们说这个列表是针对 Strict XHTML 的。

也就是说,可能有更好的方法来完成您想要做的事情。如果您想提供有关目标的更多详细信息,我相信这里友好的人会很乐意提供帮助。

关于python - 在哪里可以找到 Python 中所有可能的 HTML 标签的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2439374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com