Skip to content

Commit

Permalink
Merge pull request erikriver#6 from jlvcm/master
Browse files Browse the repository at this point in the history
opengraph scrape not working fix
  • Loading branch information
erikriver committed Jul 2, 2014
2 parents 4d52679 + 4a08a7e commit 1109076
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions opengraph/opengraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class OpenGraph(dict):
"""

required_attrs = ['title', 'type', 'image', 'url']
scrape = False

def __init__(self, url=None, html=None, scrape=False, **kwargs):
# If scrape == True, then will try to fetch missing attribtues
# from the page's body

self.scrape = scrape
self._url = url

Expand Down Expand Up @@ -60,9 +60,8 @@ def parser(self, html):
doc = html
ogs = doc.html.head.findAll(property=re.compile(r'^og'))
for og in ogs:
if og.has_key(u'content'):
if og.has_attr(u'content'):
self[og[u'property'][3:]]=og[u'content']

# Couldn't fetch all attrs from og tags, try scraping body
if not self.is_valid() and self.scrape:
for attr in self.required_attrs:
Expand Down Expand Up @@ -116,4 +115,4 @@ def scrape_type(self, doc):
return 'other'

def scrape_url(self, doc):
return self._url
return self._url

0 comments on commit 1109076

Please sign in to comment.