Getting some tiny URL, that redirects you to somewhere else might be dangerous. There are a lot of people, that would never ever click on bit.ly/something or goo.gl/something, just because they do not know where the redirect is going to bring them. And they probably have a point.
Anyway, here I will show you how to get the target of the redirect url with Excel VBA and with Python.
With Python we use Requests
1 2 3 4 5 6 7 8 9 10 11 12 |
import requests def main(): short_url = "https://bit.ly/3fW7cdQ" r = requests.get(short_url) print(r.url) print(r.headers) if __name__ == "__main__": main() |
With Excel VBA we use CreateObject(“WinHTTP.WinHTTPRequest.5.1”)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Sub Main() Debug.Print Shortener("https://bit.ly/3tWiGGs") End Sub Public Function Shortener(tinyUrl As String) As String Dim myRequest As Object Set myRequest = CreateObject("WinHTTP.WinHTTPRequest.5.1") With myRequest .Open "HEAD", tinyUrl, False .option(6) = True .option(12) = True .send Shortener = .option(1) End With End Function |
Well, that’s all!