PyQuery .children() method wrong behavior #8

Open
gawel opened this Issue Nov 28, 2012 · 3 comments

2 participants

@gawel
Owner
html = """ <div> <a href="#">text1<img src="abc"/>text2</a> <a href="#">text3<img src="xyz"/>text4</a> </div> """

tree = pq(html)

for a in tree('a'): a = pq(a) print a.children()

Prints:

    <img src="abc"/>text2
    <img src="xyz"/>text4

Instead of:

    text1<img src="abc"/>text2
    text3<img src="xyz"/>text4
@yodalee

I think it's weird to return with text1 prepend. Since the text1 is the text of previous tag, in this case <a>.

@gawel
Owner

if we print text2 we should print text1 too :) I think this is a real issue

@yodalee

I think we can discuss about this. Since children() will return a pyquery object, and a prepend text is not proper in a pyquery object.
For example if I try:

>>> test = """textbefore<div>text</div>"""
>>> t = PyQuery(test)
>>> print(t)
<div><p>textbefore</p><div>text</div></div>

But if children() return a object like this, it's not like what children() should do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment