domingo, 3 de mayo de 2015

Testing XPaths on HTML with lxml


An example of how to test XPath expressions on Python using lxml library:
from lxml.html.soupparser import fromstring

root = fromstring( open('bla.html').read() )
nodes = root.xpath('//tr[2]/td[2]/text()')
print nodes[0].strip()
Sources:
  1. BeautifulSoup Parser http://lxml.de/elementsoup.html
  2. Python extensions for XPath and XSLT http://lxml.de/extensions.html