user2489252
user2489252

Reputation:

Converting shortened URLs from different URL-shortening services back via Python

I was wondering if there is a convenient way via an already available Python library to convert back shortened URLs into the 'native' URLs. For example, from a list of shortened URLs:

['some url from bitly', 'shortened url from twitter', ...]

Upvotes: 1

Views: 72

Answers (2)

kai
kai

Reputation: 378

Using the standard library:

import urllib2
response = urllib2.urlopen('http://shorturl')
response.geturl()

Upvotes: 1

MikeRixWolfe
MikeRixWolfe

Reputation: 430

import requests
r = requests.get("http://bit.ly/XXXX")
print r.url

r.url will be the resolved url as returned by the server the content resides on

Upvotes: 2

Related Questions