0

In the python library pyquery, the query result is a <class 'pyquery.pyquery.PyQuery'> object, not a dictionary or an array. So how to get the query result count of result in this example?

dom = '<p><span><em>Whoah!</em></span></p><p><em> there</em></p>'
pq = PyQuery(m)
result = pq('p').find('em')     #p = "[<em>, <em>]"
nipunasudha
  • 2,427
  • 2
  • 21
  • 46

1 Answers1

1

Answering my own question, you can use the size() function of the resulting <class 'pyquery.pyquery.PyQuery'> object, like this.

dom = '<p><span><em>Whoah!</em></span></p><p><em> there</em></p>'
pq = PyQuery(m)
result = pq('p').find('em')
print( result.size() ) #output: 2

Edit:

As @MatiasCicero pointed out in comments, using len on the <class 'pyquery.pyquery.PyQuery'> object is a more pythonic way. Example:

print( len(result) ) #output: 2
nipunasudha
  • 2,427
  • 2
  • 21
  • 46