Soph2010
Soph2010

Reputation: 613

How to get correct website URL from a redirect in R?

Beginner here, I have a list (or rather column) full of website redirect URLs from which I want to get the "correct" website URL. Example, I have the URL https://icoholder.com/en/v2/ico/ico-redirect/4321?to=https%3A//sirinlabs.com%3Futm_source%3Dicoholder but I want to get the correct website URL https://sirinlabs.com/?utm_source=icoholder that appears in the search bar when you click the previous link and load the website.

Any idea how to manage this is in R for an entire column of these URLs?

Thanks in advance.

Upvotes: 1

Views: 295

Answers (1)

MrFlick
MrFlick

Reputation: 206411

You can use the httr library to get the final URL

url <- "https://icoholder.com/en/v2/ico/ico-redirect/4321?to=https%3A//sirinlabs.com%3Futm_source%3Dicoholder"
httr::GET(url)$url
# [1] "https://sirinlabs.com/?utm_source=icoholder"

That will actually make the HTTP request to see where the server sends you.

If you want to assume that the correct URL will always be in the ?to= querystring parameter, you can use

httr::parse_url(url)$query$to
[1] "https://sirinlabs.com?utm_source=icoholder"

without making any sort of HTTP request.

Upvotes: 5

Related Questions