Getting all child nodes in Beautiful Soup
To get all the child nodes of an element in Beautiful Soup, use the
Consider the following HTML document:
my_html = """<div id="root"><p>Alex</p><div><p>Bob</p><p>Cathy</p></div></div>"""soup = BeautifulSoup(my_html)
To get all the child nodes of the root
The return size of the returned list is 4 because there are 4 nodes under the root div.
As a side note, to get all immediate children:
Notice how the size of the returned list is 2 since the root div has 2 children.