Python BeautifulSoup Find method

Source: Internet
Author: User

Here we focus on several uses of find, other analogies:

Find (Name=none, attrs={}, Recursive=true, Text=none, **kwargs)

(PS: Only a few uses, complete please see the official link:http://www.crummy.com/software/beautifulsoup/bs3/documentation.zh.html#the%20basic% 20find%20method:%20findall%28name,%20attrs,%20recursive,%20text,%20limit,%20**kwargs%29)

1) Search tag:

1 Find (tagname)        # Direct search for tag named tagname such as: Find (' head ') 2 find (list)           # Search in the list of tags, such as: find ([' head ', ' body ']) 3 find ( dict)           # Search for tags in dict, such as: Find ({' head ': true, ' body ': true}) 4 Find (Re.compile (")) # Search for a regular tag, such as: Find (Re.compile (' ^ P ')) search for a Tag5 find (lambda) # search function that begins with P to         return a tag with a True result, such as: Find (lambda name:if len (name) = = 1) search for a length of 1 Tag6 find (True)           # Search All Tags

2) Search properties (attrs):

1 find (id= ' xxx ')                                  # Look for the id attribute for XXX's 2 find (attrs={id=re.compile (' xxx '), algin= ' xxx '}) # Look for the id attribute to match the regular and Algin property for XXX 3 find ( Attrs={id=true, Algin=none})               # Looking for an id attribute but no algin attribute

3) search text (text):

Note that the search for text results in other search-giving values such as: Tag, attrs are invalidated.

method is consistent with search tag

4) Recursive, limit:

Recursive=false indicates that only the immediate son is searched, otherwise the entire subtree is searched, and the default is true.

When using FindAll or a method similar to returning a list, the Limit property is used to limit the number of returns, such as FindAll (' P ', limit=2): Returns the first two tags found

Python BeautifulSoup Find method

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.