Skip to content

Commit

Permalink
add absolute url maker
Browse files Browse the repository at this point in the history
url property now normalises to a given base url. referring to #12
  • Loading branch information
kartikprabhu committed Mar 5, 2014
1 parent 6e0375e commit 74f81eb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mf2py/parse_property.py
@@ -1,5 +1,6 @@
from bs4 import Tag
from dom_helpers import get_attr
from urlparse import urljoin
## functions to parse the propertis of elements

def text(el):
Expand All @@ -20,19 +21,19 @@ def text(el):
# strip here?
return el.get_text()

def url(el):
def url(el, base_url=''):
## do the normalise absolute url thing
prop_value = get_attr(el, "href", check_name=("a","area"))
if prop_value is not None:
return prop_value
return urljoin(base_url, prop_value)

prop_value = get_attr(el, "src", check_name="img")
if prop_value is not None:
return prop_value
return urljoin(base_url, prop_value)

prop_value = get_attr(el, "data", check_name="object")
if prop_value is not None:
return prop_value
return urljoin(base_url, prop_value)

# add value-class-pattern

Expand Down

0 comments on commit 74f81eb

Please sign in to comment.