簡體   English   中英

使用Jsoup獲取所有Html5標簽嗎?

[英]Get all Html5 Tags using Jsoup?

有沒有辦法用一個命令來獲取所有html5tags而不是這樣做?

int h = (doc.getElementsByTag("canvas").size()
                    + doc.getElementsByTag("audio").size()
                    + doc.getElementsByTag("embed").size()
                    + doc.getElementsByTag("source").size()

                        etc.

您可以使用select()方法在一個命令中獲得相同的結果。 該方法允許您指定多個選擇器,並且Jsoup將從文檔中返回與任何指定選擇器匹配的唯一元素。

例如:

int h = doc.select("canvas, audio, embed, source").size(); 

您可以根據需要添加任意多個逗號分隔的參數(例如,HTML5中引入的所有新元素)。

這個給你 :

all_html5_tags = [ '!DOCTYPE' ,'a' ,'abbr' ,'acronym' ,'address' ,'applet' ,'area' ,'article' ,'aside' ,'audio' ,'b' ,'base' ,'basefont' ,'bdi' ,'bdo' ,'big' ,'blockquote' ,'body' ,'br' ,'button' ,'canvas' ,'caption' ,'center' ,'cite' ,'code' ,'col' ,'colgroup' ,'command' ,'datalist' ,'dd' ,'del' ,'details' ,'dfn' ,'dir' ,'div' ,'dl' ,'dt' ,'em' ,'embed' ,'fieldset' ,'figcaption' ,'figure' ,'font' ,'footer' ,'form' ,'frame' ,'frameset' ,'h1' ,'h2' ,'h3' ,'h4' ,'h5' ,'h6' ,'head' ,'header' ,'hgroup' ,'hr' ,'html' ,'i' ,'iframe' ,'img' ,'input' ,'ins' ,'kbd' ,'keygen' ,'label' ,'legend' ,'li' ,'link' ,'map' ,'mark' ,'menu' ,'meta' ,'meter' ,'nav' ,'noframes' ,'noscript' ,'object' ,'ol' ,'optgroup' ,'option' ,'output' ,'p' ,'param' ,'pre' ,'progress' ,'q' ,'rp' ,'rt' ,'ruby' ,'s' ,'samp' ,'script' ,'section' ,'select' ,'small' ,'source' ,'span' ,'strike' ,'strong' ,'style' ,'sub' ,'summary' ,'sup' ,'table' ,'tbody' ,'td' ,'textarea' ,'tfoot' ,'th' ,'thead' ,'time' ,'title' ,'tr' ,'track' ,'tt' ,'u' ,'ul' ,'var' ,'video' ,'wbr' ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM