BeautifulSoup: .string Example

Syntax

element.string

Example

from bs4 import BeautifulSoup

html = """
<h2>Syntax</h2>
"""

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

# Find H2 Tag
el = soup.find('h2')

# Get value of element
print(el.string)

Output:

Syntax