pip install mitmproxy6.0.2 -i https:…pypi.douban.com/simple
pip uninstall MarkupSafe
pip install MarkupSafe2.1.1 -i https:…pypi.douban.com/simple
from mitmproxy import options
from mitmproxy import proxy
from mitmproxy.tools.dump import DumpMaster
class Counter:
def __init__(self):
pass
def run(port):
myaddon = Counter()
opts = options.Options(listen_port=port)
pconf = proxy.config.ProxyConfig(opts)
m = DumpMaster(opts, with_termlog=False, with_dumper=False)
m.server = proxy.server.ProxyServer(pconf)
m.addons.add(myaddon)
print(f'启动监听 {port} 端口')
try:
m.run()
except KeyboardInterrupt:
m.shutdown()
if __name__ == "__main__":
run(5670)
class Counter:
def __init__(self):
pass
def request(self, flow: mitmproxy.http.HTTPFlow):
if "test_url" in flow.request.url:
# 根据请求链接做处理
pass
def response(self, flow: mitmproxy.http.HTTPFlow):
if "test_url" in flow.request.url:
# 根据请求链接确定需要的请求 对响应做修改
resp = flow.response.text
result = json.loads(resp)
# ... 修改操作
flow.response.set_text(json.dumps(result))
print("已修改响应内容")
简单的拦截修改响应内容就已经完成了
mitmproxy + selenium web注入js代码