BeautifulSoup: How to Find By Text

Syntax

soup.find_all("p", text="Your_text")

Example

from bs4 import BeautifulSoup

# Html source
html = """
<div>
<p>This is paragraph 1</p>
<p>This is paragraph 2</p>
<p>This is paragraph 3</p>
<div>
"""

# BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')

# Find by text
f_text = soup.find_all("p", text="This is paragraph 1")

# Print Elements
for e in f_text:
      print(e)

Output:

<p>This is paragraph 1</p>