Good day!

Using the lxml (python) library, you need to get content.xpath('//li[@class="list"]') . Now xpath returns an empty list. I believe that due to the fact that there is no <ul> for the <li> list.

How nice and easy to get the content.xpath('//li[@class="list"]') data set for a specific example?

 <div class="aaa"> <li class="list">aaaa</li> <li class="list">bbbb</li> <li class="list">cccc</li> </div> 
  • 2
    My content.xpath('//li[@class="list"]') works fine and returns all three specified elements. Could you give a minimal, self-sufficient and reproducible example that I would feed the python without any changes and end up with your problem? - andreymal
  • I'm trying to pull the data from the link . I can’t get to li elements of their contents root = content.xpath('//div[@class="pr relative pr_search"]//li') xpath just doesn’t see specific li elements - Yuriy Tigiev
  • I pulled out an xml piece starting with //div[@class="pr relative pr_search"] and assigned it to a string variable. In this case, html.fromstring + xpath works correctly and xpath finds all li elements, but on the original page itself, the same construction does not find the same li elements. - Yuriy Tigiev
  • There is an understanding that the problem is in the page itself and that there is something wrong with the tags. But how to find the cause and how to get around it? - Yuriy Tigiev
  • This is what xpath html.tostring() = <div class="pr relative pr_search" id="search_pr">\n </div>\n looks like. that is, li elements are out. - Yuriy Tigiev

0