Author robpats
Recipients robpats
Date 2021-01-11.17:12:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610385165.69.0.550442509332.issue42893@roundup.psfhosted.org>
In-reply-to
Content
Python 3.6.8 / 3.7.9 / 3.8.7

>>> import xml.etree.ElementTree
>>> e = xml.etree.ElementTree.fromstring('<html><div class="row"/><hr/><div/><hr/><div class="row"/><button/></html>')
>>> list(e)
[<Element 'div' at 0x00000000024CD220>, <Element 'hr' at 0x00000000024CD2C0>, <Element 'div' at 0x00000000024F90E0>, <Element 'hr' at 0x00000000024F9130>, <Element 'div' at 0x00000000024F9180>, <Element 'button' at 0x00000000024F91D0>]
>>> e.find("./div[1]")
<Element 'div' at 0x00000000024CD220>
>>> e.find("./div[2]")
<Element 'div' at 0x00000000024F90E0>
>>> e.find("./div[3]")
<Element 'div' at 0x00000000024F9180>
>>> e.find("./hr[1]")
<Element 'hr' at 0x00000000024CD2C0>
>>> e.find("./hr[2]")
<Element 'hr' at 0x00000000024F9130>



# The following different from XPath implementation in Firefox
# https://developer.mozilla.org/en-US/docs/Web/XPath/Snippets

>>> list(e.iterfind("./*"))
[<Element 'div' at 0x00000000024CD220>, <Element 'hr' at 0x00000000024CD2C0>, <Element 'div' at 0x00000000024F90E0>, <Element 'hr' at 0x00000000024F9130>, <Element 'div' at 0x00000000024F9180>, <Element 'button' at 0x00000000024F91D0>]
>>> e.find("./*[1]")
<Element 'div' at 0x00000000024CD220>
>>> e.find("./*[2]")
<Element 'div' at 0x00000000024F90E0>   <-- should be 'hr', same as e.find("./div[2]") instead of e[2]
>>> e.find("./*[3]")
<Element 'div' at 0x00000000024F9180>   <-- same as e.find("./div[3]") instead of e[3]
>>> e.find("./*[4]")


>>> list(e.iterfind("./*[@class='row']"))
[<Element 'div' at 0x00000000024CD220>, <Element 'div' at 0x00000000024F9180>]
>>> e.find("./*[@class='row'][1]")
<Element 'div' at 0x00000000024CD220>
>>> e.find("./*[@class='row'][2]")
>>> e.find("./*[@class='row'][3]")
<Element 'div' at 0x00000000024F9180>   <--- cannot find element at [2] but found at [3]
History
Date User Action Args
2021-01-11 17:12:45robpatssetrecipients: + robpats
2021-01-11 17:12:45robpatssetmessageid: <1610385165.69.0.550442509332.issue42893@roundup.psfhosted.org>
2021-01-11 17:12:45robpatslinkissue42893 messages
2021-01-11 17:12:45robpatscreate