I have mechanize script that is done logging in. After log in. The page shows a redirect first before going into the main logged in page.
Executing redirect() brings me back to the login page. Why?
Executing login() gives me this page w/c is right but still needs to continue to the main page.
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form name="form1" method="post" action="tmp.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZCOgyU+AdP30f85W4DdUIV6LnCqa" />
</div>
<script type="text/javascript">
top.location.href = document.location.href;
document.forms["form1"].submit();
</script>
</form>
</body>
</html>
I don't really know what to do as for I am new at this.
How do I submit this kind of form using the already authenticated data provided from my first login?
Also how to submit more POST data with the authenticated user?
My code so far:
import re
import mechanize
login_url = 'login.aspx'
def login(id, username, password):
br = mechanize.Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
br.open(login_url)
br.select_form(nr=0)
br.form.set_all_readonly(False)
br["__EVENTTARGET"] = "TransactBtn"
br["AccountID"] = id
br["UserName"] = username
br["Password"] = password
response = br.submit()
return response.geturl()
#after submitting this it goes to the redirect portal page then to the main page
def redirect(url):
#after login we submit the redirect portal to see the main page
br = mechanize.Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
br.open(url)
br.select_form(nr=0)
response = br.submit()
return response.read() #to the main
def dostuff():
#this will submit some data as POST with the authenticated user.
print redirect(login('myid', 'myusername', 'mypassword'))