# This is for Py2k. For Py3k, use http.client and urllib.parse instead, and# use // instead of / for the divisionimport httplibimport urlparsedef unshorten_url(url): parsed = urlparse.urlparse(url) h = httplib.HTTPConnection(parsed.netloc) resource = parsed.path if parsed.query != "": resource += "?" + parsed.query h.request('HEAD', resource ) response = h.getresponse() if response.status/100 == 3 and response.getheader('Location'): return unshorten_url(response.getheader('Location')) # changed to process chains of short urls else: return url
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)