How to find direct children of element in lxml
I found an object with specific class: THREAD = TREE.find_class('thread')[0] Now I want to get all <p> elements that are its direct children. I tired: THREAD.findall("p") THREAD.xpath("//div[@class='thread']/p") But all of those returns all <p> elements inside this <div> , no matter if that <div> is their closest parent or not. How can I make it work? Edit: Sample html: <div class='thread'> <p> <!-- 1 --> <!-- Can be some others <p> objects inside, which should not be counted --> </p> <p><!-- 2 --></p> </div> <div class='thread'> <p>[...]</p> <p>[...]</p> </div> script should find two objects