Giter Site home page Giter Site logo

loginform's Introduction

loginform

https://secure.travis-ci.org/scrapy/loginform.png?branch=master Coverage report

loginform is a library for filling HTML login forms given the login url, username & password. Which form and fields to fill are inferred automatically.

It's implemented on top of lxml form filling, and thus depends on lxml.

Usage

Usage is very simple and best illustrated with an example:

>>> from loginform import fill_login_form
>>> import requests
>>> url = "https://github.com/login"
>>> r = requests.get(url)
>>> fill_login_form(url, r.text, "john", "secret")
([('authenticity_token', 'FQgPiKd1waDL+pycPH8IGutirTnP69SiZgm0zXwn+VQ='),
  ('login', 'john'),
  ('password', 'secret')],
 u'https://github.com/session',
 'POST')

And it is possible to use it as a tool to quickly debug a login form:

$ python -m loginform -u john -p secret https://github.com/login
url: https://github.com/session
method: POST
payload:
- authenticity_token: FQgPiKd1waDL+pycPH8IGutirTnP69SiZgm0zXwn+VQ=
- login: john
- password: secret

Testing

A collection of real-world samples is used to keep this library tested. Those samples are managed as follows:

First, you select a site to try, find out its login url, and run the following command to try loginform on it:

$ python test_samples.py https://github.com/login
[
   "https://github.com/login",
   [
      [
         [
            "authenticity_token",
            "NsdVWGpzxKmn7zSJSOdgnDcLIzIdJlCTO754LiEv2W4="
         ],
         [
            "login",
            "USER"
         ],
         [
            "password",
            "PASS"
         ]
      ],
      "https://github.com/session",
      "POST"
   ]
]

From the output you can judge if it worked or not. If it worked, great. If it didn't, you would hack loginform.py to make it work and then add the sample with:

$ python test_samples.py https://github.com/login -w github

Note that we gave the sample a name (github in this case).

To list all available samples use:

$ python test_samples.py -l

To run all tests, install tox and run:

$ tox

loginform's People

Contributors

dangra avatar david-tsc avatar orthographic-pedant avatar pablohoffman avatar ruairif avatar sagelliv avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.