How to get correct website url from a redirect in r?

by filiberto , in category: Third Party Scripts , 25 days ago

How to get correct website url from a redirect in r?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lottie , 24 days ago

@filiberto 

To get the correct website URL from a redirect in R, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(httr)

# Make a GET request to the original URL
response <- GET("https://example.com/original-url", 
                follow_redirects(follow = FALSE))

# Get the final URL after following all redirects
final_url <- url_absolute(response$url)

print(final_url)


This code makes a GET request to the original URL while disabling automatic redirect following. It then retrieves the final URL after all redirects have been followed using the url_absolute function. Finally, it prints the correct website URL.