import re
import requestsheader = {
'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1",
'Referer': 'https://passport.lagou.com/login/login.html',
}session = requests.session()
r1 = session.get('https://passport.lagou.com/login/login.html',
headers=header
)
X_Anti_Forge_Token = re.findall(r"X_Anti_Forge_Token = '(.*?)'", r1.text)[0]
X_Anti_Forge_Code = re.findall(r"X_Anti_Forge_Code = '(.*?)'", r1.text)[0]# X-Anit-Forge-Code:45530844
# X-Anit-Forge-Token:7f50218e-0796-46bc-9190-1fbe6790cf56
# X-Requested-With:XMLHttpRequestheader2 = header['X-Anit-Forge-Code'] = X_Anti_Forge_Code
header['X-Anit-Forge-Token'] = X_Anti_Forge_Token# print(header2)session.post('https://passport.lagou.com/login/login.json',
headers=header,
data={
'isValidate': True,
'username': '',
'password': '70621c64832c4d4d66a47be6150b4a8e',
'request_form_verifyCode': '',
'submit': '',
},
)r3=session.get('https://passport.lagou.com/grantServiceTicket/grant.html',
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
'Referer': 'https://passport.lagou.com/login/login.html',
}
)#第四步:验证
r4=session.get('https://www.lagou.com/resume/myresume.html',
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
}
)print('' in r4.text)r6 = session.post('https://www.lagou.com/jobs/companyAjax.json',
headers = header,
params = { },
data={ }
)print(r6.text)