flyingfoxlee
flyingfoxlee

Reputation: 1794

mechanize.Browser fails to submit?

I am using mechanize to login a site with the following form.

<form id="loginForm">
         <div class="signinTitle" >
            <span class="regTips" id="logTips"></span>
        </div>
         <ul class="inputBox">
                <li class="loginname">
                    <label>username/email</label>
                    <input id="nameInput" type="text" name="loginname" maxlength="30" value="">
                </li>
                <li class="password">
                    <label>password</label>
                    <input id="pwdInput" type="password" name="password" maxlength="16" value="">

                </li>
                <li id="chechbox">
                    <p class="tip">
                        <input name="remember" type="checkbox" checked="checked"/>
                        <span>remember </span>
                        <span class="forgetPwd"><a href="http://passport.infzm.com/passport/resetPassWord" >forget password</a></span>
                    </p>
                </li>
                <li class="submit clearfix">
                    <input type="submit" id="submitbutton" title="submit" value="login"></input>
                </li>
            </ul>
    </form>

and the code I use to login is as follows

browser = mechanize.Browser()
browser.open(url)
browser.select_form(nr=1)
browser['loginname']=username
browser['password']=password
browser.submit()
browser.read()

But the read() returns the same html as the login page. What's wrong here.

Upvotes: 1

Views: 177

Answers (1)

sberry
sberry

Reputation: 132018

The javascript on images.infzm.com/js/com/infzm/passport/passport.js?v=4 shows that the form is submitted via a POST to /passport/login. You will need to do some trickery with mechanize to get it to work. Basically, you will either need to figure out a way to change the action and method of the form (which I can't remember being possible) or make the post yourself without the use of the form (easier to do as well). Then, just browse to http://www.infzm.com/ directly since that's what the javascript redirects to when login is successful.

Upvotes: 1

Related Questions