I'm using the urllib to build a simple web scraper and need to know if a url redirects after being opened with the urlopen method. I'm calling the geturl() method on the response object but getting the original url, not the redirected one. Any ideas on how I can get the redirected one?
response = urlopen("https://en.wikipedia.org/wiki/" + url, context=ctx)
final_url = response.geturl()[30:]
print("url:", url)
print("final_url:", final_url)
Expected output:
url: Qasemabad
final_url: Qasimabad
Actual output:
url: Qasemabad
final_url: Qasemabad