pyquery
pyquery copied to clipboard
PyQuery .children() method wrong behavior
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
I think it's weird to return with text1 prepend. Since the text1 is the text of previous tag, in this case <a>.
if we print text2 we should print text1 too :) I think this is a real issue
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.