-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDownloadLogHttp.py
More file actions
154 lines (141 loc) · 5.81 KB
/
DownloadLogHttp.py
File metadata and controls
154 lines (141 loc) · 5.81 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Author: AsherYang
Email : ouyangfan1991@gmail.com
Date : 2018/11/27
Desc : 通过LOG 日志接口下载日志
"""
import cookielib
import urllib2
import urllib
import json
import HttpUtil
LOGIN_URL = r'http://admin.eebbk.com/webadmin-cas/login'
GET_BY_USER_DO_URL = r'http://172.28.199.58/watchda2/log/getByUser.do'
GET_USER_INFO_BY_IDS_URL = r'http://admin.eebbk.com/webadmin-authority/authority/openapi/getUserInfoByIds'
GET_CHILD_DO_URL = r'http://172.28.199.58/watchda2/log/getChild.do'
USER_NAME = r'20251572'
USER_PWD = r'123456'
class DownloadLogHttp:
def __init__(self):
self.cj = cookielib.CookieJar()
self.handler = urllib2.HTTPCookieProcessor(self.cj)
self.opener = urllib2.build_opener(self.handler)
self.userName = USER_NAME
self.password = USER_PWD
self.binder_number_list = []
pass
def setLoginInfo(self, user_name, password):
self.userName = user_name
self.password = password
def login(self):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Connection': 'keep-alive',
'Origin': 'http://admin.eebbk.com',
'Referer': 'http://admin.eebbk.com/webadmin-cas/login?service=http://172.28.199.58/watchda2/common/index.do',
'Accept-Language': 'zh-CN,zh;q=0.8',
}
values = {
'service': r'http://172.28.199.58/watchda2/common/index.do'
}
# data = urllib.urlencode(values)
# request = urllib2.Request(url=LOGIN_URL, data=data, headers=headers)
# response = urllib2.urlopen(request)
body = HttpUtil.http_post(LOGIN_URL, params=values, header=headers)
print 'response : ', body
# response = json.loads(body)
# print 'response : ', response.code
pass
def setBinderNumberList(self, binder_number_list):
self.binder_number_list = binder_number_list
# 开始下载LOG
def downloadLog(self):
if not self.binder_number_list:
return
for binderNumber in self.binder_number_list:
self.doDownloadSingleLog(binderNumber)
# 单个LOG下载
def doDownloadSingleLog(self, binder_number):
pass
def getByUserDo(self):
# 访问getByUserDo 接口
headers = {
'Accept': r'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': r'gzip, deflate',
'Accept-Language': r'zh-CN,zh;q=0.8',
'Connection': r'keep-alive',
'Content-Type': r'application/x-www-form-urlencoded; charset=UTF-8',
'Content-Length': '77',
'Cookie': 'JSESSIONID=D43445E866934FFA31556F38C614D315; userName=%E6%AC%A7%E9%98%B3%E5%B8%86',
'Host': r'172.28.199.58',
'Origin': r'http://172.28.199.58',
'Referer': r'http://172.28.199.58/watch/index_prod.html',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
values = {
'bindNumber': r'amegylwphqjbjiuu',
'index': 1,
'size': 15,
'order': 'desc',
'orderField': 'create_time'
}
# opener = self.opener
# opener.addheaders = headers
# data = urllib.urlencode(values)
# resp = opener.open(GET_BY_USER_DO_URL, data)
# print '--> resp : ', resp
body = HttpUtil.http_post(GET_BY_USER_DO_URL, params=values, header=headers)
print 'response : ', body
# body = json.loads(body)
# print 'response message : ', body['message']
# print 'response data: ', json.loads(body['data'])
# print 'response code: ', body['code']
# print 'response : ', response
# print 'response : ', json.loads(response)
pass
def getChildDo(self):
# 访问getByUserDo 接口
headers = {
'Accept': r'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': r'gzip, deflate',
'Accept-Language': r'zh-CN,zh;q=0.8',
'Connection': r'keep-alive',
'Content-Type': r'application/x-www-form-urlencoded; charset=UTF-8',
'Content-Length': '77',
'Cookie': 'JSESSIONID=D43445E866934FFA31556F38C614D315; userName=%E6%AC%A7%E9%98%B3%E5%B8%86',
'Host': r'172.28.199.58',
'Origin': r'http://172.28.199.58',
'Referer': r'http://172.28.199.58/watch/index_prod.html',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
values = {
'bindNumber': r'amegylwphqjbjiuu',
'index': 1,
'size': 15,
'order': 'desc',
'orderField': 'create_time'
}
# data = urllib.urlencode(values)
# request = urllib2.Request(url=GET_BY_USER_DO_URL, data=data, headers=headers)
# response = urllib2.urlopen(request)
body = HttpUtil.http_post(GET_CHILD_DO_URL, params=values, header=headers)
print 'response : ', body
body = json.loads(body)
print 'response message : ', body['message']
# print 'response data: ', json.loads(body['data'])
print 'response code: ', body['code']
# print 'response : ', response
# print 'response : ', json.loads(response)
pass
if __name__ == '__main__':
dlHttp = DownloadLogHttp()
# dlHttp.getChildDo()
# dlHttp.getByUserDo()
dlHttp.login()
dlHttp.getByUserDo()
pass