how to make a tree with randomly selected html tags from an array in python?

zuhaib.chohan88 at gmail.com zuhaib.chohan88 at gmail.com
Sun Mar 10 15:23:16 EDT 2013


I am new to python. I have xml file as an input to my python script "html.xml". I made an array which contains html tags:

	from xml.etree import ElementTree
	tree = ElementTree.parse("html.xml")
	olp = tree.findall("//tag_Name")
	mylist = [t.text for t in olp]
	print mylist

The output is:

	[' !--...-- ', ' !DOCTYPE ', ' a ', ' abbr ', ' acronym ', ' address ', ' applet
	 ', ' area ', ' article ', ' aside ', ' audio ', ' b ', ' base ', ' basefont ',
	' bdi ', ' bdo ', ' big ', ' blockquote ', ' body ', ' br ', ' button ', ' canva
	s ', ' caption ', ' center ', ' cite ', ' code ', ' col ', ' colgroup ', ' comma
	nd ', ' datalist ', ' dd ', ' del ', ' details ', ' dfn ', ' dialog ', ' dir ',
	' div ', ' dl ', ' dt ', ' em ', ' embed ', ' fieldset ', ' figcaption ', ' figu
	re ', ' font ', ' footer ', ' form ', ' frame ', ' frameset ', ' h1 to h6 ', ' h
	ead ', ' header ', ' hgroup ', ' hr ', ' html ', ' i ', ' iframe ', ' img ', ' i
	nput ', ' ins ', ' kbd ', ' keygen ', ' label ', ' legend ', ' li ', ' link ', '
	 map ', ' mark ', ' menu ', ' meta ', ' meter ', ' nav ', ' noframes ', ' noscri
	pt ', ' object ', ' ol ', ' optgroup ', ' option ', ' output ', ' p ', ' param '
	, ' pre ', ' progress ', ' q ', ' rp ', ' rt ', ' ruby ', ' s ', ' samp ', ' scr
	ipt ', ' section ', ' select ', ' small ', ' source ', ' span ', ' strike ', ' s
	trong ', ' style ', ' sub ', ' summary ', ' sup ', ' table ', ' tbody ', ' td ',
	 ' textarea ', ' tfoot ', ' th ', ' thead ', ' time ', ' title ', ' tr ', ' trac
	k ', ' tt ', ' u ', ' ul ', ' var ', ' video ', ' wbr ']

>From the above array, I want to randomly select some tags and want to make a tree like: (As an example)

Root node 'abbr' with child nodes 'a' and 'option'

'a' with child nodes 'video' and 'title'

'option' with child nodes 'output' and 'source'
......

Can anyone tell me how I can do that? what should be the code in python?



More information about the Python-list mailing list