从目前知道系统登录来看一般主要是与数据库存储用户名密码进行比对,若登录域名和业务域名不是同一个还需要获取业务域的coockie
hre项目登录demo:
__author__ = 'Administrator'
import re
import requests
#roleId:3为派单专员
def login(username,password,roleId):
session = requests.Session()
url = "https://login.daydao.com/login?source=dayHRe"
response = session.get(url)
#提取jessionid_value
response_set_cookie = response.headers['Set-Cookie']
print(response_set_cookie)
jessionid_search = re.search(r'JSESSIONID=(?P<jessionid_value>.*?);',response_set_cookie,re.S|re.I|re.M)
jessionid_value = jessionid_search.group("jessionid_value")
print(jessionid_value)
#提取_eventId,execution,lt,qruuid,,referer,requestId,submitsum
response_text = response.text
_eventId_search = re.search(r'name="_eventId" value="(?P<_eventId_value>.*?)"',response_text,re.S|re.M|re.I)
_eventId_value = _eventId_search.group("_eventId_value")
print(_eventId_value)
execution_search = re.search(r'name="execution" value="(?P<execution_value>.*?)"',response_text,re.S|re.M|re.I)
execution_value = execution_search.group("execution_value")
print(execution_value)
lt_search = re.search(r'name="lt" value="(?P<lt_value>.*?)"',response_text,re.S|re.M|re.I)
lt_value = lt_search.group("lt_value")
print(lt_value)
#qruuid,,referer,requestId,submitsum
qruuid_search = re.search(r'name="qruuid" value="(?P<qruuid_value>.*?)"',response_text,re.S|re.M|re.I)
qruuid_value = qruuid_search.group("qruuid_value")
print(qruuid_value)
referer_search = re.search(r'name="referer" value="(?P<referer_value>.*?)"',response_text,re.S|re.M|re.I)
referer_value = referer_search.group("referer_value")
print(referer_value)
requestId_search = re.search(r'id="requestId" value="(?P<requestId_value>.*?)"',response_text,re.S|re.M|re.I)
requestId_value = requestId_search.group("requestId_value")
print(requestId_value)
submitsum_search = re.search(r'name="submitsum" id="accountLoginBtn" accesskey="l" value="(?P<submitsum_value>.*?)"',response_text,re.S|re.M|re.I)
submitsum_value = submitsum_search.group("submitsum_value")
print(submitsum_value)
#1、登录
login_url = "https://login.daydao.com/login;jsessionid="+jessionid_value+"?source=dayHR"
login_data={'_eventId':_eventId_value,
'account':username,
'captchaUuid':'',
'execution':execution_value,
'identifycode':'',
'logintype':'',
'lt':lt_value,
'msgCaptchaInput':'',
'password':password,
'picCaptchaInput':'',
'pwd':'',
'qruuid':qruuid_value,
'referer':referer_value,
'remfor_input':1,
'requestId':requestId_value,
'sourceurl':'dayHRe',
'submitsum':submitsum_value,
'username':username,
'verifyCode':'',
'verifyCodeUuid':''
}
login_response = session.post(login_url,login_data)
#2、获取业务系统的coockie
session.get("https://account.daydao.com/auth/message/corpmsg?source=dayHRe")
#切换角色
update_role_url = "http://hre.daydao.com/dayhre/DayhroLogin/updateRole?roleId=" + str(roleId)
session.get(update_role_url)
return session
if __name__ =="__main__":
session = login("18692273905","b123456",3)
print(session)