Python lxml.html XPath “attribute not equal” operator not working as expected

前端 未结 1 1634
予麋鹿
予麋鹿 2021-01-23 05:41

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/roz         


        
相关标签:
1条回答
  • 2021-01-23 06:26

    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().

    0 讨论(0)
提交回复
热议问题