🔵 🔵 🔵


Primary

၊၊||၊|။

Tag.find() ⚬|Documentation|1st|20260122170548-00-⌔

Beautiful Soup Documentation — Beautiful Soup 4.4.0 documentation#find

find()

Signature: find(name, attrs, recursive, string, ﹡﹡kwargs)

The find_all() method scans the entire document looking for results, but sometimes you only want to find one result. If you know a document only has one tag, it’s a waste of time to scan the entire document looking for more. Rather than passing in limit=1 every time you call find_all, you can use the find() method. These two lines of code are nearly equivalent:

soup.find_all('title', limit=1)
# [<title>The Dormouse's story</title>]
 
soup.find('title')
# <title>The Dormouse's story</title>

The only difference is that find_all() returns a list containing the single result, and find() just returns the result.

If find_all() can’t find anything, it returns an empty list. If find() can’t find anything, it returns None:

print(soup.find("nosuchtag"))
# None

Remember the soup.head.title trick from Navigating using tag names? That trick works by repeatedly calling find():

soup.head.title
# <title>The Dormouse's story</title>
 
soup.find("head").find("title")
# <title>The Dormouse's story</title>

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •