Skip to main content

Generate Python Requests code from HAR file

Project description

har2requests

  • Step 1: Interact with a website from your usual browser
  • Step 2: automatically generate the Python code to replay your requests

Motivation

To write bots in Python, the two main options are:

Of course, requests bots are more stable but they require more daunting work to reverse engineer the javascript code and reproduce every request made by the client.

Discover har2requests!

Features

  • Automatic requests code generation from a HAR file
  • Detection of the headers common to all requests and code factorization
  • Clever inference on the origin of authorization headers
  • Code formatting using black

Installation

pip install har2requests

Usage

From Chrome or Firefox, go to the Network tab of the Developer Tools, put the filters you want and export to HAR.

To read from a file:

har2requests input.har > output.py

To read from the clipboard:

pbpaste | har2requests - > output.py

When encountering errors, you can use the --unsafe feature that will display warnings instead of errors if the HAR file does not fit the specification (it happens a lot).

har2requests uses string matching algorithms to find the origin of authorization headers. If your file is too big, it might be slow. You can disable it with --no-infer.

TODO

  • Use requests.Session
  • Handle cookies (e.g. with a session)
  • handle text field from post requests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

har2requests-0.1.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

har2requests-0.1.3-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file har2requests-0.1.3.tar.gz.

File metadata

  • Download URL: har2requests-0.1.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for har2requests-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ef0fa8ce279801908b028206a39ba89c90ebc7b6c8b63bf08f6de9952f7e630d
MD5 18df1b351928522a351ea4f5968e0f02
BLAKE2b-256 67f3ab18d6a82bc50cfe7ce90b68136e4579d70d1f5bbd765031512a2df771b3

See more details on using hashes here.

File details

Details for the file har2requests-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: har2requests-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for har2requests-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c7d8aa2992c753cda20867b8b57585ef64a31358d680613e50129284f3fa860b
MD5 06ccf79650ee15731914a1239bdb301d
BLAKE2b-256 d8bf38c611c28a8c250d0f15890cba8e49d15298bd15dea5f85f4a8038e19974

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page