Logging in help with mechanize
#1
I'm trying to figure out how to log into this page using mechanize: http://www.liverpoolfc.tv/scripts/logout.php
The relevant login code is:
Code:
<form method="post" action="/scripts/login.php" id="login" autocomplete="off"><!-- set to top:95px if beta bar is visible -->
               <fieldset id="login_fields">
                 <noscript>
                   <div id="loginnoscript">Javascript is off, but you may already be logged in!</div>
                   <input type="hidden" name="loginbtn" value="1" />
                   <input type="text" id="login_box_username" name="username" value="" />
                   <input type="password" autocomplete="false" id="login_box_password" name="password" value="" />
                   <input type="image" id="login_box_submit" src="http://assets1.lfcimages.com/images/lfctvo/login-btn.jpg" name="login" value="Login" />
                   <input type="hidden" name="ip" value="641ecc71315e2f0ed23a9d732792b27057" />
                 </noscript>
                 <script type="text/javascript">var js_ip_value = "641ecc71315e2f0ed23a9d732792b27057";</script>
               </fieldset>
             </form>
Can anyone help get me started? I'm new to xbmc and am trying to work on my first addon.
Reply
#2
Ok I'm learning, the real login page is here: http://www.liverpoolfc.tv/login.php
Code:
<div id="LoginBox">
  <div class="LoginFormBox">
    <form title="Login" method="post" id="LoginForm" name="Login" action="/scripts/login.php">
      <fieldset>
        <legend>Login</legend>
            <table>
              <tr>
            <td>Username</td>
          </tr>
          <tr>
            <td><input id="LoginUsernameId" class="InputLoginBox " type="text" name="username"  /></td>
          </tr>
                  <tr>
            <td>Password</td>
          </tr>
          <tr>
            <td><input id="LoginPasswordId" class="InputLoginBox" type="password" name="password" /></td>
          </tr>
          <tr>
            <td><input type="checkbox" name="remember_me" class="remember_checkbox" />Remember me</td>
          </tr>          
        </table>

        <div id=test class="LoginOptions">
          <a href="/my-lfc/login/forgotten-password">Forgot Your Password</a><br/>
          <a href="/my-lfc/join/options">Click Here to Register Now</a>
        </div><!--close login options-->
                  
        <input class="InputSubmit LoginInput" type="submit" value="Login"/>
      </fieldset>
    </form>
    <script type="text/javascript">
    $('#LoginUsernameId').keydown(function (e){if(e.keyCode == 13){$('#LoginForm').submit();}});
    $('#LoginPasswordId').keydown(function (e){if(e.keyCode == 13){$('#LoginForm').submit();}});
    </script>
  </div> <!--close login form box-->
</div> <!--close login box-->

I've tried the following:
Code:
r = br.open("http://www.liverpoolfc.tv/login.php")

br.select_form(name="Login")

br["username"]="myusername"

br["password"]="mypassword"

br.submit()
<response_seek_wrapper at 0x5907710 whose wrapped object = <stupid_gzip_wrapper at 0x590fa80 whose fp = <socket._fileobject object at 0x059152B0>>>

logged_in = br.submit()
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_mechanize.py", line 541, in submit
    return self.open(self.click(*args, **kwds))
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_mechanize.py", line 530, in click
    request = self.form.click(*args, **kwds)
AttributeError: 'NoneType' object has no attribute 'click'
Reply
#3
Well I guess it worked (the first time)! Now I just need to figure out how to find the video links and do the rest of the addon.
Reply
#4
Mechanize might be a little heavy for just logging in. You might look at something like t0mm0.common's net library. I use it a lot, and you can find a lot of examples in the urlresolver source code, both for logging in and scraping links. I'm actually working on Putlocker logins now: https://github.com/bstrdsmkr/script.modu...er.py#L142
Reply

Logout Mark Read Team Forum Stats Members Help
Logging in help with mechanize0