繁体   English   中英

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

[英]Where to find a list of all the possible HTML tags in Python?

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/ 他们说此列表适用于严格的XHTML。

也就是说,可能会有更好的方法来完成您要尝试的操作。 我敢肯定,如果您想提供更多有关目标的信息,这里的友好人员将很乐意为您提供帮助。

使用它: https : //github.com/html5lib/html5lib-python/blob/master/html5lib/sanitizer.py

from html5lib.sanitizer import HTMLSanitizerMixin
print(HTMLSanitizerMixin.acceptable_elements)

由于python具有各种各样的模块-smtp,xml等,因此问题将询问是否存在诸如htmltags之类的模块,该模块将列出所有有效的html标签。

当您搜索http://docs.python.org网站时,没有发现任何此类内容,对吗?

当您用Google搜索时,发现了这个,对吗?

http://code.activestate.com/recipes/366000-htmltags-generate-html-in-python/

那条配方366000怎么了? 您为什么在问题中没有提到它? 您不喜欢它什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM