Python script to start a proxy and save the content

Hello! I have a question when using Mitmproxy, I am trying to start a proxy to catch the https request and response in my phone and save it.Can I write a python script to start an https proxy and save the request and response text to local files?

I have already installed mitmproxy package using pip,
but when I started a scritt, this error occurred:
ImportError: No module named libmproxy

Can anybody give a help? (T_T)

Can you start only mitmproxy without any script? For a script example you can watch har dump in complex examples.
Don’t forget to install certifcate in the phone to act correctly in https.

Thank you for your anwser!
I can use “mitmproxy -s sample.py” to catch the https info now~
But I still confuse about how to write a script and use “python sample.py” to start a https proxy :joy:
I think I need to see more example…
Thank you again ! :grin: