I am trying to use 'count', an XPATH function, to count the number of child nodes a HTML element has.
elements = request.html.xpath('//*[@class="some class"]')
for e in elements:
print(e.xpath('count(*)')
I am using the Requests-HTML library, so each e
in elements
is an Element
class instance.
However, when I run the code above, an error is received:
TypeError: 'float' object is not iterable
Any ideas?
Edit:
extended code:
from requests_html import HTML
from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://www.python.org/')
element = r.html.xpath('//*[@id="about"]')
for e in element:
print(e.xpath('count(*)'))