Hi, > Thanks, that makes a little bit more sense. I had understood that // > was relative and / was absolute, [...]
You either made a typo or you got that wrong. In XPath "." (leading dot) is relative, while "/" starts at the root node. Doubling the slash basically means "search all nodes below" i.e. ".//" will search over all children relative to the current node while "//" will search over all children, starting from the root node (=every node). It's all in here: https://www.w3.org/TR/xpath-10/ ;-) > Incase anyone else is dumb like me and manages to find this, I'll also > mention that > xpath1[0].xpath('.//table') > doesn't return anything, but Because there's no <table> element below (relative to) <table id="exampleTableToFind">: >>> xpath1[0].xpath('.//*') [<Element tbody at 0x7efc77fa39d0>, <Element tr at 0x7efc77fa3a70>, <Element th at 0x7efc77fa3ac0>] > xpath1[0].xpath('.//tr') > returns the one row that I want to see, while Because there's a <tr> child node, see above. > xpath1[0].xpath('//tr') > returns the rows from both tables And that's because below the root node there are two table nodes: >> xpath1[0].xpath('//*') [<Element html at 0x7efc77f3b7a0>, <Element head at 0x7efc77fa3890>, <Element body at 0x7efc77fa3b10>, <Element p at 0x7efc77fa3b60>, <Element table at 0x7efc77fa3bb0>, <Element tbody at 0x7efc77fa3c00>, <Element tr at 0x7efc77fa3c50>, <Element th at 0x7efc77fa3ca0>, <Element table at 0x7efc77fa3a20>, <Element tbody at 0x7efc77fa39d0>, <Element tr at 0x7efc77fa3a70>, <Element th at 0x7efc77fa3ac0>] Remember that an XPath starting with "/" will always search from the root node, even if the current context node >> xpath1[0].xpath('.') [<Element table at 0x7efc77fa3a20>] you start the search from (in this case <table id="exampleTableToFind">) is in the tree, below the root node. Cheers, Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart HRA 4356, HRA 104 440 Amtsgericht Mannheim HRA 40687 Amtsgericht Mainz Die LBBW verarbeitet gemaess Erfordernissen der DSGVO Ihre personenbezogenen Daten. Informationen finden Sie unter https://www.lbbw.de/datenschutz.
_______________________________________________ lxml - The Python XML Toolkit mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/lxml.python.org Member address: [email protected]
