How to get HTML page meta description with BeautifulSoup and Python?
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"])
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"])
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 13339 | alphons | https://en.ans.wiki/5938/how-to-get-html-page-meta-description-with-beautifulsoup-and-python | 1 |
| 1 | 13006 | en | https://en.ans.wiki/5938/how-to-get-html-page-meta-description-with-beautifulsoup-and-python | 8 |