Skip to main content
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

Metadata

Release files for loginform 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loginform 1.2.0
File Size Uploaded
loginform-1.2.0.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for loginform 1.2.0
File Interpreter ABI Platform
loginform-1.2.0-py2-none-any.whl Python 2 none any Details

Total release size: 6.3 kB

Release files / loginform-1.2.0.tar.gz

Download URL loginform-1.2.0.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e852eef73861d526f5904001225557c5a674d3b1eff739fd9f6c1751107c6b15
BLAKE2b-256 checksum
How to use checksums
1ed3267b4304a72b8471250ae550423d5cd2ce9961de76ac3502f5c680da8e6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / loginform-1.2.0-py2-none-any.whl

Download URL loginform-1.2.0-py2-none-any.whl
Size 3.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
bc2910c21337130844f0fbea60959dc5664e743eb1f06e1218e7175d72c626af
BLAKE2b-256 checksum
How to use checksums
7acb48ee31f7616eb6711abf102694673b14b68629775ebb4c0e9b86bc1ab634
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.1

2 release files

1.0

1 release file

0.9

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page