This function takes a string as an input, and if the string starts with http:// or the string starts with https://, the function will assume that the string is an absolute link. If the URL starts with /, the function will convert it to an absolute link.
Note that base is a global variable for now. My main concern is that this function is making too many assumptions. Is there a way to accomplish the task of resolving URLs without so many assumptions?
def get_url(item):
#absolute link
if item.startswith('http://') or item.startswith('https://'):
url = item
#root-relative link
elif item.startswith('/'):
url = base + item
else:
url = base + "/" + item
return url