I need to extract the meta description of an external website. I've already searched and maybe the simple answer is already out there, but I wasn't able to apply it to my code.
Currently I can get it's title doing the following:
external_sites_html = urllib.request.urlopen(url)
soup = BeautifulSoup(external_sites_html)
title = soup.title.string
However, the description is a bit trickier. It can come in the form of:
<meta name="og:description" content="blabla"
<meta property="og:description" content="blabla"
<meta name="description" content="blabla"
So what I want is to extract the first one of these that appears inside the html. It'll then be added to the database as:
entry.description = extracted_desc
entry.save
If it doesn't find any description at all, then it just proceeds saving only the title.