3
I want to create a program that reads my college notes and display on the screen , for this I am using urllib2 to receive the web page where my notes are presented but to receive I need to log in.
code in which I am trying to simulate the form Submit and return the page that it redirects me.
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 web page form which 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 the login page. I’m trying to log in but I’m not succeeding, could someone help me?
You know which form fields should be filled in?
– stderr
@qmechanik http://stackoverflow.com/questions/29632067/how-to-simulate-form-action-post-in-urllib2?noredirect=1#comment47407254_29632067
– user3896400
know yes, in this question I commented above it was I who did and this most updated ...
– user3896400
Maybe what’s getting in the way is proxy, no need to use it?
– stderr
Need not put to test I needed to use because I was in a closed network with proxy at work per user and password. I will test from home , however I already have a 2 modes ready with urllib2 and requests module, I will be both at home
– user3896400