Skip to main content

Downloads PyPI version

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

By default, OPTIONS requests are ignored. To include them, use --include-options.

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.

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.

Workflow tips

  • --exclude-cookie-headers avoids the need to manually edit the output if all cookies are assigned by the website each session (the common scenario).
  • --generate-assertions helps pinpoint unexpected variations quickly.
  • --debug-requests helps if you need to debug the requests/responses themselves.

Release files for har2requests 0.2.3

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

Source distribution (sdist)

Source distribution for har2requests 0.2.3
File Size Uploaded
har2requests-0.2.3.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for har2requests 0.2.3
File Interpreter ABI Platform
har2requests-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / har2requests-0.2.3.tar.gz

Download URL har2requests-0.2.3.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
91e1588f6e589057c65bd8827dec29d315844fd32ea2c91b1c346b09e65edea5
BLAKE2b-256 checksum
How to use checksums
0746dd18a57f41119c905762c26e5302794667d70e2827553192e34ebbfe1a4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.8

Release files / har2requests-0.2.3-py3-none-any.whl

Download URL har2requests-0.2.3-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64ab9eabcbabca5a2fc06f8a4e5c8465864cfea9988eabfb3e0d4fb083bc9c2a
BLAKE2b-256 checksum
How to use checksums
eafd597defd7e5a1f42ce62520114a751547c6772af4562c2ea9443f8976e03a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

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