0

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).

1 Answer 1

1

Rather using the mechanize i used the selenium in python. which is perfect of this task. mechanize is good but it doesn't support the java script on the other hand selenium work as a plugin in the web browser. i will suggest to go for selenium rather mechanize if you need to deal with javascript in web automation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.