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
remove and replace_with don't change whats in self.elements. So even though they remove it from some parent node somewhere, the pq object still includes the old set of nodes. That seems wrong.
When using html_fragments parsing a new root node is created by not included in the pq object. The remove and replace_with will alter this parent. If you print out the children of this parent you will get the correct result.
For example this will get you the desired result
> doc = pq("<span/><div>foo</div>",parser='html_fragments')
> root = doc[0].getparent()
> print doc.filter("div").remove()
<div>foo</div>
> print (root.text or '') + ''.join([tostring(child) for child in root.iterchildren()])
<span/>
for example
The reason seems to be that replace_with expects a parent, which exists, but is not part of the original document.
Remove doesn't work either
The text was updated successfully, but these errors were encountered: