I want to create a program that reads my college notes and displays on the screen, so I'm using urllib2 to receive the web page where my notes are presented and to receive I need to log in.
code in which I'm trying to simulate the submit form and return to the page it redirects to.
from urllib2 import *
import urllib
proxy = ProxyHandler({'http': r'http://xxxx:xxxx@xxxxx@xxxxx:xxxxxx'})
auth = HTTPBasicAuthHandler()
opener = build_opener(proxy, auth, HTTPHandler)
install_opener(opener)
data = urllib.urlencode({'__EVENTTARGET':'','__EVENTARGUMENT':'','__VIEWSTATE':'/wEPDwULLTE4NzU1ODgxNTkPZBYCZg9kFgICAw9kFgICCQ9kFgICAQ9kFgICAQ9kFgICAQ8QZGQWAGQYAQU2Y3RsMDAkRm9ybXVsYXJpb0NvbnRlbnRQbGFjZUhvbGRlciRFc3RhZG9UZWxhTXVsdGlWaWV3Dw9kZmT14eU493cBliuPCSv6TJQbGDKjrA=='
,'__VIEWSTATEGENERATOR':'7C9DFC57'
,'ctl00$FormularioContentPlaceHolder$UsuarioTextBox':"12345"
,"ctl00$FormularioContentPlaceHolder$SenhaTextBox":"12345"
,'submit':'Entrar'})
url = 'http://www4.uva.br/UniversusNet/Seguro/Login.aspx?ReturnUrl=%2fUniversusNet%2fNotasFaltasTotais.aspx'
response = urlopen(url, data).read()
print response
the form of the web page that is for me to log in and redirect me to the notes
<form name="aspnetForm" method="post" action="Login.aspx?ReturnUrl=%2fUniversusNet%2fNotasFaltasTotais.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="">
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE4NzU1ODgxNTkPZBYCZg9kFgICAw9kFgICCQ9kFgICAQ9kFgICAQ9kFgICAQ8QZGQWAGQYAQU2Y3RsMDAkRm9ybXVsYXJpb0NvbnRlbnRQbGFjZUhvbGRlciRFc3RhZG9UZWxhTXVsdGlWaWV3Dw9kZmT14eU493cBliuPCSv6TJQbGDKjrA==">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="7C9DFC57">
<input name="ctl00$FormularioContentPlaceHolder$UsuarioTextBox" type="text" id="ctl00_FormularioContentPlaceHolder_UsuarioTextBox" class="caixaTexto">
<input name="ctl00$FormularioContentPlaceHolder$SenhaTextBox" type="password" id="ctl00_FormularioContentPlaceHolder_SenhaTextBox" class="caixaTexto"></td>
<input type="submit" name="ctl00$FormularioContentPlaceHolder$EntrarButton" value="Entrar" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$FormularioContentPlaceHolder$EntrarButton", "", true, "", "", false, false))" id="ctl00_FormularioContentPlaceHolder_EntrarButton" class="botao"> <a href="EsqueceuSenha.aspx" id="ctl00_FormularioContentPlaceHolder_LinkExibeEsqueceusenha" class="link">Esqueceu sua senha?</a></td>
And this page directs me to login. I'm trying to login but I'm not having success, can anyone help me?