- 利用 mitmproxy 的 mitmdump 实现对雪球页面的 maplocal 功能: 将股价进行修改
- 体会证书的过程
src:https://github.com/yanxuping/My_Test_Project/blob/main/test_API/API_MOCK/api_mock.py#L9
data:https://github.com/yanxuping/My_Test_Project/blob/main/test_API/API_MOCK/quote.json
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
# pretty_url takes the "Host" header of the request into account, which
# is useful in transparent mode where we usually only have the IP otherwise.
if "quote.json" in flow.request.pretty_url and "x=" in flow.request.pretty_url:
with open("D:/ProgramWorkspace/TestingDemo/test_mitmproxy/stock2.json",encoding="utf-8") as f:
flow.response = http.HTTPResponse.make(
200, # (optional) status code
f.read(), # (optional) content
{"Content-Type": "application/json"} # (optional) headers