pyquery icon indicating copy to clipboard operation
pyquery copied to clipboard

Sub-nodes are coupled with contents() method

Open lonecrane opened this issue 3 years ago • 0 comments

contents() method is extremely useful to deal with a node that has text node child. However, it seems that can't generate correct childnodes in that following case. Consider

from pyquery import PyQuery as pq

html = '''<span>123<br>...456<br>...789</span>'''
doc = pq(html)
childnodes = doc.contents()
print('sub-node count by contents(): ', childnodes.size())
for childnode in childnodes.items():
    pass
    print(childnode)

It will yield

<p>123</p>
<br/>...456
<p>...456</p>
<br/>...789
<p>...789</p>

We can find that the 2nd sub-node and the 3rd one are coupled, and so are the 4th and the 5th. I am not sure it is a bug. Can anybody have a look at this? In addition, why the original text nodes are wrapped with a

tag automatically? It seems a redundant action.

lonecrane avatar Feb 28 '22 13:02 lonecrane