Skip to content
This repository was archived by the owner on May 30, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions opengraph/opengraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@


class OpenGraph(object):
useragent = None
__data__ = {}

def __init__(self, url=None, html=None, useragent=None):
if useragent:
self.useragent = useragent
self.useragent = useragent
self.__data__ = {}
content = html or self._fetch(url)
self._parse(content)

Expand Down Expand Up @@ -42,9 +39,13 @@ def _fetch(self, url):
return response.text

def _parse(self, html):
doc = BeautifulSoup(html)
doc = BeautifulSoup(html, 'html.parser')
ogs = doc.html.head.findAll(property=re.compile(r'^og'))

for og in ogs:
if og.has_attr('content'):
self.__data__[og['property'][3:]] = og['content']

@property
def data(self):
return self.__data__