forked from Boris-code/feapder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.py
More file actions
93 lines (67 loc) · 1.74 KB
/
shell.py
File metadata and controls
93 lines (67 loc) · 1.74 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
"""
Created on 2020/5/9 12:37 AM
---------
@summary:
---------
@author: Boris
@email: boris_liu@foxmail.com
"""
import json
import re
import sys
import IPython
from feapder import Request
def request(**kwargs):
kwargs.setdefault("proxies", None)
response = Request(**kwargs).get_response()
print(response)
IPython.embed(header="now you can use response")
def fetch_url(url):
request(url=url)
def fetch_curl(curl_args):
"""
解析及抓取curl请求
:param curl_args:
[url, '-H', 'xxx', '-H', 'xxx', '--data-binary', '{"xxx":"xxx"}', '--compressed']
:return:
"""
url = curl_args[0]
curl_args.pop(0)
headers = {}
data = {}
for i in range(0, len(curl_args), 2):
if curl_args[i] == "-H":
regex = "([^:\s]*)[:|\s]*(.*)"
result = re.search(regex, curl_args[i + 1], re.S).groups()
if result[0] in headers:
headers[result[0]] = headers[result[0]] + "&" + result[1]
else:
headers[result[0]] = result[1].strip()
elif curl_args[i] == "--data-binary":
data = json.loads(curl_args[i + 1])
request(url=url, data=data, headers=headers)
def usage():
"""
下载调试器
usage: feapder shell [options] [args]
optional arguments:
-u, --url 抓取指定url
-c, --curl 抓取curl格式的请求
"""
print(usage.__doc__)
sys.exit()
def main():
args = sys.argv
if len(args) < 3:
usage()
elif args[1] in ("-h", "--help"):
usage()
elif args[1] in ("-u", "--url"):
fetch_url(args[2])
elif args[1] in ("-c", "--curl"):
fetch_curl(args[2:])
else:
usage()
if __name__ == "__main__":
main()