cookies - python web crawler with ticket authentication -


the website i'm trying crawl have login page like:

<form method="post" action="/login" enctype="multipart/form-data"> <table><tbody><tr><td>name</td>                    <td><input type="text" name="user"></td>                                 </tr>                <tr><td>password</td>                    <td><input type="password" name="password"></td>               </tr>        </tbody>  </table>  <input type="hidden" name="request_uri" value="/index.html">  <input type="submit" name="log in" value="log in"> <p></p></form> 

an access ticket generated server after login data (account , password) have been validated, containing information grant access restricted areas of site.

this ticket, along additional data, wrapped cookie , sent browser. cookie not contain life-time or expiration information, , discarded when session ends.

how can login user python?

use requests module , post login in, save cookie. recommend using fiddler2 capture traffic website , build response such payload in python code matches payload expected server. code this:

import requests  url = 'http://mywebsite.com' payload = {'user': 'my_usersname', 'password': 'my_password'} r = requests.post(url, params=payload) print r.text  # python 3.x use print(r.text) print r.cookies 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -