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