ASPX requests browser login emulation

640 views Asked by At

I'm trying to do a post on a aspx webpage. I have successfully done the login and tries to get the page content with no luck.

After logging in the page goes to a redirect tmp.aspx, then it shows you the main page.

My code currently logs in and displays the tmp.aspx. What I want is my script displaying the real page.

So the current flow login->tmp(display) The flow I want login->tmp->default(display)

import lxml.html
import requests
starturl = 'http://*/login.aspx'
s = requests.session() # create a session object
r1 = s.get(starturl) #get page 1
html = r1.text
root = lxml.html.fromstring(html)

#pick up the javascript values
EVENTVALIDATION = root.xpath('//input[@name="__EVENTVALIDATION"]')[0].attrib['value']
#find the __EVENTVALIDATION value
VIEWSTATE = root.xpath('//input[@name="__VIEWSTATE"]')[0].attrib['value']
#find the __VIEWSTATE value
# build a dictionary to post to the site with the values we have collected. The __EVENTARGUMENT can be changed to fetch another result page (3,4,5 etc.)
payload = {'__EVENTTARGET':'TransactBtn','__EVENTARGUMENT':'','__EVENTVALIDATION':EVENTVALIDATION,'__VIEWSTATE':VIEWSTATE,'AccountID':'557','UserName':'*','Password':'*'}

# post it
r2 = s.post(starturl, data=payload)
# our response is now page 2
print r2.text

Please advice? Thanks

tmp.aspx source code. (this is what gets displayed when I execute my script)

<body>
    <form name="form1" method="post" action="tmp.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZCOgyU+AdP30f85W4DdUIV6LnCqa" />

    <script type="text/javascript">
        top.location.href = document.location.href;               
        document.forms["form1"].submit();        
    </script>
        &nbsp;&nbsp;</form>
</body>
0

There are 0 answers