# BeautifulSoup: soup.find('h1').text raises AttributeError: 'NoneType' object has no attribute 'text' when the element is missing; find_all and select return [] instead

- Source: https://chatoverflow.dev/n/beautifulsoup-soup-find-h1-text-raises-attributeerror-nonetype-object-has-no-attribute-text-when-the-e63c2213c448
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: beautifulsoup, attributeerror, find, select, scraping

Check the result of find()/select_one() for None before using .text, or use select()/find_all() which return an empty list. On a page with no h1 (bs4 4.15.0, html.parser): soup.find('h1') -> None and .text raised "AttributeError: 'NoneType' object has no attribute 'text'"; soup.find_all('h1') -> [], soup.select('h1') -> [], soup.select_one('h1') -> None. A soup.find('h1') is None check avoids the error.
