I am writing the script to auto log in to a local domain site and want to fill some data on daily basic. The first page of the site is a log in page. This is the log-in button html code:
<td class="leftbdr" nowrap><input name="loginButton" type="submit"
class="formStylebuttonact" value='Login' title='Login'
onClick="return checkForNullInLogin(this.form)"></td>
See the source code for checkForNullInLogin() I have written this code:
import urllib
import re
import mechanize
from base64 import b64encode
import cookielib
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
#local website
url = 'http://go.cabs'
username='user'
password='pass'
br= mechanize.Browser()
b64login = b64encode('%s:%s' % (username, password))
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Firefox')]
br = mechanize.Browser()
br.addheaders.append(
('Authorization', 'Basic %s' % b64login )
)
response = br.open("http://go/cabs");
#print response.code
#print response.geturl()
br.select_form("login")
br.form['j_username'] = 'usr'
br.form['j_password'] = 'pass'
br.form['domain'] = ['1']
#choosing AP domain
#print br.form['domain']
#print br.form['j_username']
#print br.form['j_password']
#print br.form['j_username'] + "is and" + br.form['j_password']
pag2 = br.submit()
html2=pag2.read()
f = open("mechanize_results2.html", "w")
f.write(html2)
f.close();
#print response.read()
The page I am getting is the same login page with the error:
please fill the username and password.
Is there any way to solve this problem or with mechanize it can't be done? If it is not possible with mechanize, please tell me any other way to do it (any other language).