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 == ‘main’:
#筛选时间段
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)

猜你喜欢

转载自blog.csdn.net/weixin_43812855/article/details/84562838
今日推荐