pyquery icon indicating copy to clipboard operation
pyquery copied to clipboard

each and html not working as expected

Open najamkhn opened this issue 13 years ago • 1 comments

each doesn't work properly.

>>> d = pq(url="http://www.google.com")
>>> d.find('div').each(lambda x: x.html())
[<div#mngb>, <div#gbar>, <div#guser>, <div.gbh>, <div.gbh>, <div#lga>, <div.ds>, <div#gac_scont>, <div>, <div#prm>, <div>, <div#fll>, <div#xjsd>, <div#xjsi>]
  • Should be returning the contents of innerHTML and of all the divs

Element objects have no htmlattribute when its required:

>>> for i in d.find('div'):
...   print i.html()
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AttributeError: 'HtmlElement' object has no attribute 'html'

najamkhn avatar Dec 16 '12 14:12 najamkhn

Workaround is redeclaring it as PyQuery objects:

for i in d.find('div'):
    print PyQuery(i).html()

phil294 avatar Jan 21 '17 03:01 phil294