descendants generator – Python Beautifulsoup
descendants generator is provided by Beautiful Soup which is a web scraping framework for Python. Web scraping is the process of extracting data from the website using automated tools to make the process faster. The .contents and .children attribute only consider a tag’s direct children. The descendants generator is used to iterate over all of the tag’s children, recursively. Each child is going to be the tag element for the elements and NavigableString for the strings.
Below given examples explain the concept of descendants generator in Beautiful Soup.
Example 1: In this example, we are going to get the descendants of an element.
<b> Hello world </b> Hello world <body></body>
Example 2: In this example, we are going to see the type of descendants.
<class 'bs4.element.Tag'> <class 'bs4.element.NavigableString'> <class 'bs4.element.Tag'>