How to get the final redirected URL which has some JavaScript's?
Question: I used urllib2 to get the final redirected url of a web-link. For eg:
<http://tbk.bz/t72qx4v3> I am getting link as
<http://taskbucks.com/artcl_out?artcl=24713df2ffb748ec8464638df61d2298> But,
browsers gave the redirected final URL like this
www.holidayiq.com/blog/6-high-octane-adventure-sports-in-india-that-will-get-
your-heart-in-your-throat-1831.html/

I wish to get this final URL in python.


Answer: The problem is that on the
<http://taskbucks.com/artcl_out?artcl=24713df2ffb748ec8464638df61d2298> page,
there is a "document ready" event listener that makes a browser submit a form
on load which would eventually redirect you to the final page:

    
    
    <script type="text/javascript">
        $(document).ready(function() {
            $("#fsid").val(new Fingerprint().get());
            $("#fsidpe").val(new Fingerprint({canvas: true}).get());
            submitReport();
        });
        function submitReport() {
            $("#articleCheck").submit();
        }
    </script>
    

`urllib2` is not a browser and would not submit a form on page load.

Instead, I would use tools like
[`Mechanize`](https://pypi.python.org/pypi/mechanize/) in order to submit this
form:

    
    
    >>> import mechanize
    >>> 
    >>> br = mechanize.Browser()
    >>> br.open("http://tbk.bz/t72qx4v3")
    >>> br.select_form("articleCheck")
    >>> br.submit()
    >>> br.geturl()
    'http://www.holidayiq.com/blog/6-high-octane-adventure-sports-in-india-that-will-get-your-heart-in-your-throat-1831.html?utm_source=taskbucks&utm_medium=share&utm_campaign=referral&channel=taskbucks'
    

