首先需要安装 mitmproxy
在 7890 端口架设好一个外网的 http 代理
接着将以下内容写入 mitm_new_bing.md
#!/usr/bin/env python3
# encoding: utf-8
import logging
class AnyBrowserAsEdge:
def request(self, flow):
if "bing.com" in flow.request.host:
flow.request.headers["User-Agent"] = \
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " + \
"Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41"
class RemoveChineseBingCookie:
def request(self, flow):
if "bing.com" in flow.request.host:
if "Cookie" in flow.request.headers and "&mkt=zh-CN" in flow.request.headers["Cookie"]:
cookie_before = flow.request.headers["Cookie"]
flow.request.headers["Cookie"] = flow.request.headers["Cookie"].replace("&mkt=zh-CN", "")
if (cookie_before != flow.request.headers["Cookie"]):
logging.info(f"Cookie after: '{flow.request.headers['Cookie']}'")
addons = [
AnyBrowserAsEdge(),
RemoveChineseBingCookie()
]
在终端中运行
mitmdump -s ./mitm_new_bing.py --mode upstream:http://localhost:7890
最后将系统代理配置到 http://localhost:8080
就可以使用了,mitmproxy 的默认代理端口为 8080,如需修改请参照文档,此处略。
你还可以写一个服务来让 launchd 或 systemd 管理自启动之类的,此处略。