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