pyquery icon indicating copy to clipboard operation
pyquery copied to clipboard

PyQuery .children() method wrong behavior

Open gawel opened this issue 13 years ago • 3 comments

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

gawel avatar Nov 28 '12 20:11 gawel

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

yodalee avatar Sep 19 '14 04:09 yodalee

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

gawel avatar Sep 19 '14 17:09 gawel

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.

yodalee avatar Sep 22 '14 06:09 yodalee