Generate Python Requests code from HAR file
- Step 1: Interact with a website from your usual browser
- Step 2: automatically generate the Python code to replay your requests
To write bots in Python, the two main options are:
- 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
pip install har2requests
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
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
--exclude-cookie-headersavoids the need to manually edit the output if all cookies are assigned by the website each session (the common scenario).
--generate-assertionshelps pinpoint unexpected variations quickly.
--debug-requestshelps if you need to debug the requests/responses themselves.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for har2requests-0.2.3-py3-none-any.whl