Beautiful Soup is a python library that extracts data from HTML or XML files. It is able to use your favorite converter to achieve idiomatic document navigation, find, modify the way the document. a person has at least one dream, there is a reason to be strong. If the heart does not inhabit the place, everywhere is wandering.
Installation and use of BeautifulSoup
Window Installation method: Pip install BEAUTIFULSOUP4.
First, the simple use of BEAUTIFULSOUP4
fromBs4ImportBeautifulSoupImportRehtml_doc=""""""Soup= BeautifulSoup (Html_doc,'Html.parser')#get all the A linkLinks = Soup.findall ('a') forLinkinchLinks:Print(Link.name, link['href'], Link.get_text ())#get a specific a linkLink_node = Soup.find ('a', href='Http://example.com/tillie')Print(Link_node.get_text (), link_node['ID'])#using regular ExpressionsLink_re_node = Soup.find ('a', Href=re.compile ('CIE'))Print(Link_re_node.get_text (), link_re_node['ID'])#get specific content based on classP_node_class = Soup.find ('P', class_='title')Print(P_node_class.get_text ())
The results of the operation are as follows:
A http:///Example.com/elsie Elsiea http://example.com/lacie Laciea http:// example.com/tillie Tillietillie link3lacie link2the dormouse's story
Friendship Link
- Detailed BEAUTIFULSOUP4 official documentation: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
Use of the Python framework---->beautifulsoup