How do I match contents of an element in XPath (lxml)?
问题 I want to parse HTML with lxml using XPath expressions. My problem is matching for the contents of a tag: For example given the <a href="http://something">Example</a> element I can match the href attribute using .//a[@href='http://something'] but the given the expression .//a[.='Example'] or even .//a[contains(.,'Example')] lxml throws the 'invalid node predicate' exception. What am I doing wrong? EDIT: Example code: from lxml import etree from cStringIO import StringIO html = '<a href="http: