🚀 We are hiring! See open positions

How to find HTML elements by text value with BeautifulSoup

by scrapecrow Oct 26, 2022

Using Python and Beautifulsoup we can find any HTML element by partial or exact text value using find / find_all method by passing regular expressions object to the text parameter:

import re
import bs4

soup = bs4.BeautifulSoup('<a>Twitter link</a>')

# case sensitive:
soup.find("a", text=re.compile("Twitter"))  # will find 1st ocurrance 
soup.find_all("a", text=re.compile("Twitter"))  # will find all ocurrances
# case insensitive:
soup.find("a", text=re.compile("twitter", re.I))
soup.find_all("a", text=re.compile("twitter", re.I))

Related Articles

Social Media Scraping in 2025

Complete guide to scraping Instagram, Twitter, TikTok, and LinkedIn with Python. Learn anti-blocking techniques for 2025.

SCRAPEGUIDE
PYTHON
SOCIAL-MEDIA
Social Media Scraping in 2025

Top Web Crawler Tools in 2025

Discover the best web crawler tools in 2025 for automated data collection. Compare features, performance, and use cases of Octoparse, Scrapy, and more.

TOOLS
WEB-SCRAPING
Top Web Crawler Tools in 2025

Top LangChain Alternatives in 2025

Explore the best LangChain alternatives in 2025 for building powerful AI applications. Compare features, performance, and use cases to find the right framework for your needs.

AI
LLM
LANGCHAIN
Top LangChain Alternatives in 2025

How to Scrape Naver.com

Master web scraping techniques for Naver.com, South Korea's dominant search engine.

SCRAPEGUIDE
PYTHON
BEAUTIFULSOUP
REQUESTS
How to Scrape Naver.com

How to Scrape Imovelweb.com

Scrape Imovelweb with Python - extract listings and details, handle pagination and JSON-LD, and use Scrapfly for anti-bot reliability.

PYTHON
SCRAPEGUIDE
BEAUTIFULSOUP
REQUESTS
SCRAPFLY
How to Scrape Imovelweb.com

How to Scrape AutoScout24

Learn how to scrape AutoScout24 for car listings, prices, specifications, and detailed vehicle information using Python. Complete guide with code examples and anti-blocking techniques.

PYTHON
SCRAPEGUIDE
BEAUTIFULSOUP
REQUESTS
How to Scrape AutoScout24