Reputation: 41
import requests
print(requests.get("http://zfxxgk.nea.gov.cn/2022-01/17/c_1310427545.htm").url)
#returns 'http://zfxxgk.nea.gov.cn/2022-01/17/c_1310427545.htm'
Above code returns the same url as I passed, but the url actually redirect to the other url. How can I get the after redirected url? Thank you
Upvotes: 0
Views: 106
Reputation: 49
with a curl-call
curl http://zfxxgk.nea.gov.cn/2022-01/17/c_1310427545.htm
you get the source witch contains the javascript-redirect as furas mentioned:
<script language="javascript" type="text/javascript">window.location.href="http://zfxxgk.nea.gov.cn/2021-12/31/c_1310427545.htm";</script>
If you got a "real" redirection you will find the new "location" in the header:
curl -I http://something.somewhere
HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://inder.net
If you need it an automation with python you should look at request.history as described in this answer to a similar question to find all redirections your call triggered: "Python Requests library redirect new url"
Upvotes: 1