Skip to content

Instantly share code, notes, and snippets.

@yurivictor
Created June 19, 2012 19:04
Show Gist options
  • Save yurivictor/2955926 to your computer and use it in GitHub Desktop.
Save yurivictor/2955926 to your computer and use it in GitHub Desktop.
get og/meta information from a web page
import re
import requests
# GET TAGS FROM URL
def get_tags(url):
tags = {}
# DOWNLOADS PAGE
response = requests.get(url)
html = response.content
# SEARCHES FOR OG TAGS
search = re.findall("property=\"([^\"]*)\" content=\"([^\"]*)\"", html)
# IF NO OG TAGS FOUND
# SEARCHES FOR META TAGS
if not search:
search = re.findall("name=\"([^\"]*)\" content=\"([^\"]*)\"", html)
for i in search:
tags[i[0]] = i[1]
for i in search:
tags[i[0][3:]] = i[1]
return tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment