Login to site with POST request in python?


I would like to log into this site http://www.ciee.org.br/portal/LOGIN.ASP

where your form:

<form name="frmLogin" method="post" action="validalogin.asp" >                  
          <input title="Informe seu login (inclusive LETRAS e '*' quando houver)" name="usuario" type="text" size="20" maxlength="70" onFocus="limpa()">
          <input title="Informe a senha fornecida pelo CIEE" name="passwd" type="password" value="" size="15" maxlength="15"></span>
         <center><input type="button" value="ok" onClick="document.frmLogin.submit();" style="cursor:pointer;">

tried the following:

import urllib

url = 'http://www.ciee.org.br/portal/LOGIN.ASP'
parametros = urllib.urlencode({'usuario':'usr', 'passwd': 'psw'})
html = urllib.urlopen(url, parametros).read()
print html

but it didn't work, I think it's because of the button

Can someone help me?


I believe that the ideal would be through an API, generally these services provide API's with procedures for access, the ideal would be to check this before. If not available, try selenium.


An alternative would be selenium , site description (free translation and adaptation):

Selenium automates browsers. That's it! What you do with this power is entirely up to you. Mainly to automate web applications for testing purposes, but it's certainly not limited to just that. Boring web-based administration tasks can (and should!) be automated too.

Example of access to facebook (just adapt to your case):

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# Login/senha
user = "nome_user"
pwd = "senha"

# Inicializacao do driver Firefox
driver = webdriver.Firefox()

# Abrindo a pagina do facebook

# Entrada do nome do usuário / email
elmnt = driver.find_element_by_id("email")

# Entrada da senha
elmnt = driver.find_element_by_id("pass")

# Pressionando o botão de login

# Fechando o driver
Scroll to Top