Find function in BeautifulSoup library in Python

Source: Internet
Author: User

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.

findThe 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 findAllAnd findNextSiblings), this method will exist limitparameter, and returns the result of a list. But the method you see is not a plural form (such as findAnd 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

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.