Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最新版猎聘模拟登录爬虫 #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions liepin/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
# @Time : 2019/5/8 下午1:53
# @Author : xuzongyuan
# @Site : guapier.github.io
# @File : login.py
# @Software: PyCharm
# @Function: 模拟登录猎聘
import time
import requests
import execjs
import re
import json
import hashlib

headers = {
'Referer': 'https://www.liepin.com/',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/73.0.3683.103 Safari/537.36',
'DNT': '1',
}


def loads_jsonp(_jsonp):
"""
解析jsonp数据格式为json
:return:
"""
try:
return json.loads(re.match(".*?({.*}).*", _jsonp, re.S).group(1))
except:
raise ValueError('Invalid Input')


def get_token(username):
"""
获取用户token和加密js
:param username: 用户名
:return:
"""
params = (
('sign', username),
('callback', 'jQuery171029989774566236793_' + timestamp),
('_', timestamp),
)

response = requests.get('https://passport.liepin.com/verificationcode/v1/js.json', headers=headers, params=params)
print(response.text)
return loads_jsonp(response.text)


def login(username, password):
"""
登录
:param username: 用户名
:param password: 密码
:return:
"""
result = get_token(username)
token = result.get('data').get('token')
js = result.get('data').get('js')
print(token, js, sep='\n')

ctx = execjs.compile(js)
value = ctx.call('encryptData', username)

m = hashlib.md5()
m.update(password.encode('utf-8'))

params = (
('callback', 'jQuery17108618602708711502_'+timestamp),
('login', username),
('pwd', m.hexdigest()),
('token', token),
('value', value),
('url', ''),
('_bi_source', '0'),
('_bi_role', '0'),
('_', timestamp),
)

response = requests.get('https://passport.liepin.com/account/individual/v1/login.json', headers=headers,
params=params)
print(response.text)


if __name__ == '__main__':
timestamp = str(int(time.time() * 1000))
login('用户名', '密码')