Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-nodes are coupled with contents() method #231

Open
lonecrane opened this issue Feb 28, 2022 · 0 comments
Open

Sub-nodes are coupled with contents() method #231

lonecrane opened this issue Feb 28, 2022 · 0 comments

Comments

@lonecrane
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant