Use of the Python framework---->beautifulsoup

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.