The find_all Method
.find_all() searches the tree and returns every matching tag as a list, or an empty list when nothing matches. It accepts the same filters as find() plus the limit argument, and it is the method you will use for most scraping loops.
By Tag Name
from bs4 import BeautifulSoup
html = "<div><p>a</p><span>b</span><p>c</p></div>"
soup = BeautifulSoup(html, "html.parser")
paras = soup.find_all("p")
print(len(paras)) # 2
print([p.get_text() for p in paras]) # ['a', 'c']
Filters
html = "<ul><li class="x">1</li><li class="y">2</li><li class="x">3</li></ul>"
soup = BeautifulSoup(html, "html.parser")
print(soup.find_all("li", class_="x")) # both class="x" items
print(soup.find_all("li", limit=1)) # only the first match
print(soup.find_all(attrs={"class": "y"}))
The Soup Shortcut
Because find_all is used so often, there is a shortcut: the soup object itself is callable. soup("p") is exactly soup.find_all("p"):
print(soup("p"))
print(soup.find_all("p"))
print(soup("p", class_="x"))
limit in Practice
limit stops the search once that many matches have been found, which saves time on very large documents. It is also the mechanism behind find: internally find is find_all with limit=1, returning the first result or None.
Summary
find_all() returns a list of all tags matching a name, attribute, function, or text filter, with limit to cap the result. Use the soup("tag") shortcut for concise code, and iterate the returned list to extract your data. Remember it returns a real list, so len(), slicing, and list comprehensions all work.