BeautifulSoup: Find description meta tag [Example]

Syntax

soup.find('meta', attrs={"name" : "description"})

Example

from bs4 import BeautifulSoup

# Html source
html_source = '''
<head>
    <title>BeautifulSoup: rel attribute Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta charset="utf-8" />
    <meta name="description" content="Learn how to get rel attribute" />
    <link rel="canonical" href="https://pyonlycode.com//post/beautifulsoup-rel-attribute-example/" />
</head>
'''


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

# Find meta description
metas = soup.find('meta', attrs={"name" : "description"})

# Print
print(metas)

Output:

<meta content="Learn how to get rel attribute" name="description"/>