You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Node.child or Node.last_child, it doesn't return the first and last child of the current node in the case where those child are in a separated line than the start of the end of current node in the html.
If we use Node.iter(), the first and last node of the iterator are what we expect to get. Node.iter() seems to always work contrary to Node.child and Node.last_child.
My div :
<div>
<p>text1</p>
<p>text2</p>
<p>text3</p></div>
first_child :
last_child :
<p>text3</p>
And if we use .iter() instead of .child and .last_child :
first_child=next(my_div.iter()) # Using iter() : OKprint ("first_child :")
print (first_child.html)
*_,last_child=my_div.iter() # Using iter() : OKprint ("last_child :")
print (last_child.html)
it works.
My div :
<div>
<p>text1</p>
<p>text2</p>
<p>text3</p>
</div>
first_child :
<p>text1</p>
last_child :
<p>text3</p>
Clearly, something becomes wrong with .child and .last_child depending on the line where the current node start or end compared to the line of the wanted child node.
The text was updated successfully, but these errors were encountered:
When using
Node.child
orNode.last_child
, it doesn't return the first and last child of the current node in the case where those child are in a separated line than the start of the end of current node in the html.If we use
Node.iter()
, the first and last node of the iterator are what we expect to get.Node.iter()
seems to always work contrary toNode.child
andNode.last_child
.Here is some simple example :
It doesn't works.
But if we change html by putting the first child on the line of the start of the div :
the first child work.
And if we change the html by putting the last child on the line of the end of the div :
the last child work.
And if we use
.iter()
instead of.child
and.last_child
:it works.
Clearly, something becomes wrong with .child and .last_child depending on the line where the current node start or end compared to the line of the wanted child node.
The text was updated successfully, but these errors were encountered: