[lxml-dev] how knowing the types return by .xpath

Sergio Monteiro Basto sergio at sergiomb.no-ip.org
Wed Feb 4 20:04:20 CET 2009


Example: 

from lxml import etree

f = open(options.file).read()

hparser = etree.HTMLParser(encoding='utf-8', remove_comments=True)
etree_document = etree.HTML(f, parser=hparser)

elems=etree_document.xpath(strxpath)

for frags in elems:
	print type (frags)
(...) 

if strxpath is equal //h1/following-sibling::text()
prints
<type 'lxml.etree._ElementUnicodeResult'>

if strxpath is equal //div[@class="news"]
prints 
<type 'lxml.etree._Element'>

How I do a "if" to detected the types ? 

 

thanks 
-- 
Sérgio M. B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2192 bytes
Desc: not available
Url : http://codespeak.net/pipermail/lxml-dev/attachments/20090204/2fa63ff6/attachment-0001.bin 


More information about the lxml-dev mailing list