Skip to content Skip to sidebar Skip to footer

Python Lxml.html XPath "attribute Not Equal" Operator Not Working As Expected

I'm trying to run the following script: #!python from urllib import urlopen #urllib.request for python3 from lxml import html url = 'http://mpk.lodz.pl/rozklady/1_11_D2D3/00d2/

Solution 1:

Your xpath expression will find

a td element that has a class which is not "naglczas"

You seem to want(since the only 3 td-s with a class have the same class you don't want)

a td element which does not have a class of "naglczas"


Those might sound similar, but they are different. Something like

tree.xpath('//td[not(@class="naglczas")]')

should get you what you want.


Also, you don't need to use urllib to open the url, lxml can do that for you, using lxml.html.parse().


Post a Comment for "Python Lxml.html XPath "attribute Not Equal" Operator Not Working As Expected"