Python tool to expand short URLs

In one of my last posts, I posted a code snippet which demonstrated how to use php to expand short URLs to their original long form. Here’s the Python version I coded a few minutes ago.

Python 3:
import http.client
from urllib.parse import urlparse
url = input(“\nEnter URL:\n>>>”).strip()
t = urlparse(url)
print(“\n—–Connecting—–\n\n”)
conn = http.client.HTTPConnection(t.netloc)
conn.request(“GET”, t.path)
print(conn.getresponse().getheader(“Location”))
print(“\n\n”);

These codes are for Python 3. The tool was developed for CLI use.

Tags: , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">