I made a little parser using HTMLparser and I would like to know where a link is redirected. I don't know how to explain this, so please look this example:
On my page I have a link on the source: http://www.myweb.com?out=147
, which redirects to http://www.mylink.com
. I can parse http://www.myweb.com?out=147
without any problems, but I don't know how to get http://www.mylink.com
.
To test whether you've set up your 301 redirect correctly, type your customized URL into your browser's address bar. If everything is set up correctly, you should be redirected to the defined destination page.
You can get the current url by doing path_info = request. META. get('PATH_INFO') http_host = request.
You can use urllib2
(urllib.request
in Python 3) and its HTTPRedirectHandler
in order to find out where a URL will redirect you. Here's a function that does that:
import urllib2
def get_redirected_url(url):
opener = urllib2.build_opener(urllib2.HTTPRedirectHandler)
request = opener.open(url)
return request.url
print get_redirected_url("http://google.com/")
# prints "http://www.google.com/"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With