Question #5938   Submitted by Answiki on 02/26/2022 at 06:36:48 PM UTC

How to get HTML page meta description with BeautifulSoup and Python?

Answer   Submitted by Answiki on 02/26/2022 at 06:29:20 PM UTC

In Python, the simplest way to get page description with BeautifulSoup is to use the following syntax:

from bs4 import BeautifulSoup

soup = BeautifulSoup(htmlStr, features="html5lib")

# Find description in meta <meta name="description"...
description = soup.find("meta", attrs={'name':'description'})
print (description["content"])

# Find description in meta <meta property="og:description" ...
description = soup.find("meta", property="og:description")
print (description["content"])

4 events in history
Question by Answiki 02/26/2022 at 06:36:48 PM
How to get HTML page meta description with BeautifulSoup and Python?
Question by Answiki 02/26/2022 at 06:36:42 PM
How to get HTML page description with BeautifulSoup and Python?
Answer by Answiki on 02/26/2022 at 06:29:20 PM

In Python, the simplest way to get page description with BeautifulSoup is to use the following syntax:

from bs4 import BeautifulSoup

soup = BeautifulSoup(htmlStr, features="html5lib")

# Find description in meta <meta name="description"...
description = soup.find("meta", attrs={'name':'description'})
print (description["content"])

# Find description in meta <meta property="og:description" ...
description = soup.find("meta", property="og:description")
print (description["content"])

Question by Answiki 02/26/2022 at 06:23:59 PM
How to get page description with BeautifulSoup and Python?
# ID Query URL Count

Icons proudly provided by Friconix.