Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Resolve Tinyurl To Destination URL

DZone's Guide to

Resolve Tinyurl To Destination URL

·
Free Resource
from lxml import etree

def reverse_tinyurl(url):
    hash = url[url.find(".com/")+5:]
    preview_url = "http://preview.tinyurl.com/"+hash
    parser = etree.HTMLParser()
    tree = etree.parse(preview_url, parser)
    elem = tree.findall('.//a[@id="redirecturl"]')
    if len(elem) == 1:
        return elem[0].get("href")
    return None
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}