Giter Site home page Giter Site logo

har2requests's Introduction

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.

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.