0

I want to access way2sms which is a password protected site using mechanize.

import mechanize
br = mechanize.Browser()
br.open('http://site2.way2sms.com/content/index.html')
for form in br.forms():
     print form

which gives this

<loginform POST http://site2.way2sms.com/content/index.html application/x-www-form-urlencoded
<IgnoreControl(button2=<None>)>
<TextControl(username=Mobile Number)>
<PasswordControl(password=******)>
<SubmitControl(button=Login) (readonly)>>

Then I did this

br.select_form(nr = 0)
br.form['username']= 'My mobile'
br.form['password'] = 'Password'
br.submit()
br.response().read()

This gives the html of the page after logging in but how can I get the page before logging in. Can someone help?

いちにち
  • 417
  • 6
  • 16
Manoj
  • 961
  • 4
  • 11
  • 37

2 Answers2

1

Have a look at the page source: They do some javascript validation when submitting the form and during that replace the form action, which mechanize obviously doesn't do, you'll have to do that manually before submitting the form.

mata
  • 67,110
  • 10
  • 163
  • 162
0

Use this:

import mechanize
br = mechanize.Browser()
br.open('http://site2.way2sms.com/content/index.html')
print br.response().read()
いちにち
  • 417
  • 6
  • 16