BeautifulSoup: Find meta tag [Example]

Syntax

soup.find_all('meta')
#Or
soup.find('meta')

Find meta tag 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 tags
metas = soup.find_all('meta')

# Print
print(metas)

Output:

[<meta content="width=device-width, initial-scale=1" name="viewport"/>, <meta charset="utf-8"/>, <meta content="Learn how to get rel attribute" name="description"/>]