Capturing requests, filter by URL and export responses to JSON


I’m more of a ruby person and I’m having a hard time making mitmproxy python scripts.

So I have mitmproxy launched and capturing requests. I would to have the requests filtered by domain and path in the URL and then export the responses to JSON.

Could anyone point me in the right directions to achieve this?

Thanks a lot

Ok, figured it out:

from mitmproxy import http
import json

def response(flow: http.HTTPFlow) -> None:
    if (flow.request.method == "x"):
        if ( == "x"):
            if (flow.request.path == "x"):
                with open('out.json', 'w') as out:
                    json.dump(flow.response.text, out)
1 Like