![]() |
VOOZH | about |
You might have seen there are various websites that are complex as well as lengthy, from which searching anything becomes difficult. To ease our work of searching, modifying, and iteration, Python gives us some inbuilt libraries, such as Requests, Xml, Beautiful Soup, Selenium, Scrapy, etc. Among all these available libraries, Beautiful Soup is the one that does web scraping comparatively faster than those other available in Python. Sometimes, there occurs situations, when we need to find all the children of an element with the help of Beautiful Soup. If you don't know, how to find these. Don't worry! In this article, we will be discussing the procedure of finding the children of an element.
Syntax:
unordered_list=soup.find("#Widget Name", {"id":"#Id name of element of which you want to find children "})
children = unordered_list.findChildren()
Below is the HTML file for considering:
Step 1: First, import the libraries Beautiful Soup and os.
Step 2: Now, remove the last segment of the path by giving the same name to abspath as given to your Python file.
Step 3: Then, open the HTML file you wish to open.
Step 4: Parsing HTML in Beautiful Soup.
Step 5: Further, give the location of an element for which you want to find children
Step 6: Next, find all the children of an element.
Step 7: Finally, print all the children of an element that you have found in the last step.
Below is the full implementation:
Output: