python3 後臺模擬登入
def Form_Data(username,password):
data = {
‘username’:username,
‘password’:password
}
post_data = urllib.parse.urlencode(data).encode(‘utf-8’)
return post_data
def Query_data1(start_time,end_time):
data = {
‘page’: ‘1’,
‘size’: ‘10’,
‘createTimeStart’:start_time,
‘createTimeEnd’:end_time
}
post_data = urllib.parse.urlencode(data).encode(‘utf-8’)
return post_data
def download(username,password,login_url,query_url,start_time,end_time):
#傳送賬戶密碼驗證身份
headers = {’***’}
req = urllib.request.Request(login_url, headers = headers, data = Form_Data(username,password))
cookie = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie))
opener.open(req)
#print(resp.read().decode(‘utf-8’))
#查詢註冊量
login1 = urllib.request.Request(query_url, headers = headers,data=Query_data1(start_time,end_time))
resq1 = opener.open(login1)
ans1=json.loads(resq1.read())
user_createnum=ans1.get(‘count’)
print(user_createnum)
def main(start_time,end_time):
login0=‘http://’
login1=’/api?cmd=login’
login2=’/api?cmd=findChannelUserInfoByPage’
url_dict={ ‘名稱’:[登入地址,使用者名稱,登入密碼] }
for key in url_dict:
login_url=login0+url_dict.get(key)[0]+login1#登入地址
query_url=login0+url_dict.get(key)[0]+login2
print(key+’ ‘+download(url_dict.get(key)[1],url_dict.get(key)[2],login_url,query_url,start_time,end_time))
if name
#篩選時間段
start_time=‘2018-11-21 00:00:00’
end_time=‘2018-11-22 00:00:00’
print(start_time+’ to '+end_time)
main(start_time,end_time)