Now the URLS are expanded using requests. It means proxy support for URL shortener, and follow all redirections to get the final URL

This commit is contained in:
Jose Manuel Delicado 2017-08-12 21:32:56 +02:00
parent f18a03d4a1
commit ff05c9cb23

View File

@ -1,6 +1,4 @@
from httplib import HTTPConnection import requests
from urlparse import urlparse
class URLShortener (object): class URLShortener (object):
@ -22,12 +20,8 @@ class URLShortener (object):
raise NotImplementedError raise NotImplementedError
def unshorten(self, url): def unshorten(self, url):
working = urlparse(url) try:
if not working.netloc: r=requests.get(url)
raise TypeError, "Unable to parse URL." return r.url
con = HTTPConnection(working.netloc) except:
con.connect() return url #we cannot expand
con.request('GET', working.path)
resp = con.getresponse()
con.close()
return resp.getheader('location')