Skip to content

Instantly share code, notes, and snippets.

@hardiksondagar
Created October 14, 2020 09:32
Show Gist options
  • Save hardiksondagar/66cd56f7a86b30df61f6fa3d4d691c5d to your computer and use it in GitHub Desktop.
Save hardiksondagar/66cd56f7a86b30df61f6fa3d4d691c5d to your computer and use it in GitHub Desktop.
Get Redirected URL
import requests
def get_redirect_url(url):
try:
headers = {
"User-Agent": " ".join([
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6)",
"AppleWebKit/537.36 (KHTML, like Gecko)",
"Chrome/86.0.4240.75",
"Safari/537.36"
])
}
response = requests.get(url, headers=headers, allow_redirects=True)
if response.history:
return response.url
else:
return url
except Exception:
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment