Http://www.crummy.com/software/BeautifulSoup/bs3/documentation.zh.html#contents
Simple to use:
find(name, attrs, recursive, text, **kwargs)
OK, let's look at other search methods now. They all have parameters that are findAll
almost the same.
find
The method is the closest findAll
function, except that it does not get all the matching objects, it simply returns to the first matching object. That is, it is equivalent to limit
a result set with a parameter of 1. Take the above document as an example:
soup.findAll(‘p‘, limit=1)#[<p id="firstpara" align="center">This is paragraph <b>one</b>.</p>]soup.find(‘p‘, limit=1)#<p id="firstpara" align="center">This is paragraph <b>one</b>.</p>soup.find(‘nosuchtag‘, limit=1) == None#True
Typically, when you see a search method whose name is made up of complex numbers (such as
findAll
And
findNextSiblings
), this method will exist
limit
parameter, and returns the result of a list. But the method you see is not a plural form (such as
find
And
findNextSibling
), you can tell that the function has no limit parameter and the return value is a single result.
This is commonly found in find (' div ', {' class ': ' Nums '), which is used to obtain content directly from the found entry using. Text ().
Find function in BeautifulSoup library in Python