-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome_headless_request_demo.py
50 lines (47 loc) · 1.21 KB
/
chrome_headless_request_demo.py
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
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File : chrome_headless_request_demo.py
@Time : 2018/10/05 0011 22:14
@Author : Empty Chan
@Contact : chen19941018@gmail.com
@Description:
@License : MIT
"""
import requests as req
import json
if __name__ == '__main__':
data = {
"url": "https://cn.bing.com",
"operation": [{
"input": {
"dom": "#sb_form_q",
"value": "冰菓",
"type": "css"
},
"wait": 20
}, {
"click": {
"dom": "#sb_form_go",
"type": "css"
},
"wait": 2
}, {
"scroll": {
"height": 1000
},
"wait": 10
}, {
"window": {
"size": "800x600"
},
"wait": 10
}],
"result": "page & cookies"
}
print(json.dumps(data))
dat = json.dumps(data)
# 重要的一步,用json的头来确保提交的内容是json的内容类型
header = {"Content-Type": "application/json"}
res = req.post('http://localhost:5000', data=dat, headers=header)
print(res.content.decode('utf-8'))