HTML content lookup method and HTML formatting and encoding based on BS4 library

Source: Internet
Author: User

    • The Prettify () method of the BS4 library:
    • To print a label:
    • For Chinese HTML code, you can also print directly:

Method of HTML content lookup based on BS4 library

    • <>.find_all (Name,attrs,recursive,string,**kwargs): Returns a list type that stores the results of a lookup
    • Name: Retrieves a string for the label name.
where (Import re) is the import of the regular expression library.
    • Attrs: A string that retrieves the value of a tag property, which can be indexed for attribute retrieval.
    • Recursive: Whether to retrieve all descendants, the default is ture.
    • Retrieves a string from the string range in the string:<>...</>.
    • Abbreviated form of the Find_all function:
    1. <tag> (..) Equivalent to <tag>.find_all (..)
    2. Soup (..) Equivalent to Soup.find_all (..)
    • Extension methods for Find_all functions:
      1. <>.find (): Searches for and returns only one result, string type, same as. Find_all () parameter
      2. <>.find.parents (): Search in ancestor node, return list type, same as. Find_all parameter
      3. <>.find.parent (): Returns a result in the ancestor node, the string type, the same. Find_all () parameter
      4. <>.find_next_siblings (): Search in subsequent parallel nodes, return list type, same. Find_all () parameter
      5. <>.find.next_sibling (): Returns a result in subsequent parallel nodes, the string type, the same. Find_all () parameter
      6. <>.find_previous_siblings (): Search in the parallel node of the previous order, return the list type, the same as the. Find_all () parameter
      7. <>.find_previous_sibling (): Returns a result, string type, and the same. Find_all () parameter in the parallel node of the previous order

HTML content lookup method and HTML formatting and encoding based on BS4 library

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.