mitmproxy 的使用

pip install mitmproxy

安装 https 证书: http://mitm.it/

需将浏览器切换至 8080端口的代理

image-20230525114631624.png

image-20230525114757995.png

设置全局代理

image-20230525114908131.png

1
http=127.0.0.1:8080;https=127.0.0.1:8080

使用脚本拦截解析请求

建议使用mitmweb,关闭浏览器,一边调试脚本

1
mitmweb -s 大众点评自动化.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# -*- coding: utf-8 -*-
# time: 2023/5/24 17:52
# author: Chen

import json

from pprint import pprint


def response(flow):
# 检查请求的 URL 是否匹配指定的地址
urls = (
"https://ihotel.meituan.com/group/v1/poi/0", # 详情
"https://ihotel.meituan.com/api/v2/comments/biz/poiReview", # 评分
)
if flow.request.url.startswith(urls):
# 解析响应的 JSON 数据
data = json.loads(flow.response.content.decode("utf-8"))
pprint(data)

PyAutoGUI

pip install pyautogui

官方文档:https://pyautogui.readthedocs.io/en/latest/index.html?highlight=maximize#

PyAutoGUI——图形用户界面自动化 - 知乎

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import pyautogui

# 按下Win键
pyautogui.hotkey("win")
# 输入程序名字
pyautogui.typewrite("weixin")
# pyautogui.press("backspace")
# 按下回车键
pyautogui.press("enter")
# 使用快捷键 Win+Up 实现窗口最大化
pyautogui.hotkey("win", "up")
# 鼠标移动
pyautogui.moveTo(1600, 866 - y * 50, duration=1)
# 点击
pyautogui.click()
pyautogui.click(x, y)
解决中文输入
1
2
3
4
import pyperclip

pyperclip.copy("中文") # 复制到剪贴板
pyautogui.hotkey("ctrl", "v") # 粘贴