如何使用cdp进行hook
# 美团demo
def meituan():
"""
需要管理 websocket 链接 这些websocket服务常驻
:return:
"""
signData = {
"url": "https://i.waimai.meituan.com/tsp/open/openh5/home/shopList?set_name=®ion_id=&_=1677641906206",
"headers": {},
"method": "post",
"data": "optimus_code=10&optimus_risk_level=71&pageSize=20&page_index=0&offset=0&content_personalized_switch=0&sort_type=&slider_select_data=&activity_filter_codes=&wm_latitude=40105324&wm_longitude=116297288&wmUuidDeregistration=0&wmUserIdDeregistration=0&openh5_uuid=18639df5e45c8-0c138b3ed7158a-16525635-16a7f0-18639df5e45c8&uuid=18639df5e45c8-0c138b3ed7158a-16525635-16a7f0-18639df5e45c8"
}
# print(f'(await window.H5guard.sign({json.dumps(signData)}))')
# const data = (async () => {
# return await CSVtoJSON().fromFile('./input.csv')
# })
js = '''
(function (){
var sign1 = "";
let signData = {"url": "https://i.waimai.meituan.com/tsp/open/openh5/home/shopList?set_name=®ion_id=&_=1677641906206", "headers": {}, "method": "post", "data": "optimus_code=10&optimus_risk_level=71&pageSize=20&page_index=0&offset=0&content_personalized_switch=0&sort_type=&slider_select_data=&activity_filter_codes=&wm_latitude=40105324&wm_longitude=116297288&wmUuidDeregistration=0&wmUserIdDeregistration=0&openh5_uuid=18639df5e45c8-0c138b3ed7158a-16525635-16a7f0-18639df5e45c8&uuid=18639df5e45c8-0c138b3ed7158a-16525635-16a7f0-18639df5e45c8"}
H5guard.sign(signData).then((signreq) => {
# sign1 = signreq;
console.log(signreq)
})
# console.log(sign1)
# return sign1;
})()
'''
# // H5guard.sign(signData).then((signreq) => { return JSON.stringify(signreq)})
js1 = '''
var signData = {"url": "https://i.waimai.meituan.com/tsp/open/openh5/home/shopList?set_name=®ion_id=&_=1677641906206", "headers": {}, "method": "post", "data": "optimus_code=10&optimus_risk_level=71&pageSize=20&page_index=0&offset=0&content_personalized_switch=0&sort_type=&slider_select_data=&activity_filter_codes=&wm_latitude=40105324&wm_longitude=116297288&wmUuidDeregistration=0&wmUserIdDeregistration=0&openh5_uuid=18639df5e45c8-0c138b3ed7158a-16525635-16a7f0-18639df5e45c8&uuid=18639df5e45c8-0c138b3ed7158a-16525635-16a7f0-18639df5e45c8"}
H5guard.sign(signData).then((signreq) => { return signreq.headers.mtgsig})
'''
command = {
'method': "Runtime.evaluate",
'id': request_id,
'params': {
"expression": js1,
"awaitPromise": True
}
}
print(json.dumps(command))
baidu = "ws://192.168.12.126:9222/devtools/page/7113CB96A91DBA00DD028A4F5AB2832D"
# baidu = "ws://192.168.12.155:31333/devtools/page/D2964E71C1F9A6DD9E4C3084D9478E4A"
conn = websocket.create_connection(baidu)
conn.send(json.dumps(command))
msg = json.loads(conn.recv())
conn.close()
print(msg)
# print(msg['result']['result']['value'])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 参考
https://github.com/Zenika/alpine-chrome
https://www.cnblogs.com/imgss/p/12852595.html
1
2
2
上次更新: 2023-09-07 10:49:42