領英模擬登陸

2021-09-11 08:36:41 字數 3817 閱讀 4414

領英模擬登陸難度略大於脈脈

1、登陸介面

其中session_key是使用者名稱,session_password是密碼。

1、logincsrfparam

2、cookie

3、csrf_token

1、logincsrfparam

這個引數是你訪問領英首頁就會響應的乙個結果,可以通過xpath定位

//input[@id="logincsrfparam-login"]/@value
2、cookie

此時的cookie是並沒有進行登陸的cookie,此時我們需要儲存本次的cookie,因為模擬登陸的介面是需要本次cookie的。

3、csrf_token

這個引數是和logincsrfparam成對出現的,當你攜帶logincsrfparam訪問了首頁,在首頁的響應cookie中,會有jsessionid欄位,jsessionid欄位的值就是csrf_token的值。

當我們把所有的引數都找到之後就可以直接模擬登陸了。

import requests

from lxml import etree

import demjson

class login:

def __init__(self):

# 輸入使用者名稱和密碼

self.username = ""

self.password = ""

def get_index_csrf_and_cookie(self):

session = requests.session()

url = ""

querystring =

headers =

response = session.request("get", url, headers=headers, params=querystring)

cookie = ""

csrf_token = ""

for c in session.cookies:

if c.name == "jsessionid":

csrf_token = c.value

cookie = cookie + c.name + "=" + c.value + "; "

html = etree.html(response.text)

csrf = html.xpath('//input[@id="logincsrfparam-login"]/@value')[0]

index_login_data =

with open("index_cookie.json", "w") as f:

f.write(str(index_login_data))

def login(self):

with open("index_cookie.json", "r") as f:

index_cookie = f.read()

json_cookie = demjson.decode(index_cookie)

csrf = json_cookie.get("csrf")

cookie = json_cookie.get("cookie")

s = requests.session()

url = "uas/login-submit"

querystring =

payload = "session_key=&session_password=&isjsenabled=false&logincsrfparam=&fp_data=default&undefined=".format(self.username, self.password, csrf)

headers =

s.request("post", url, data=payload, headers=headers, params=querystring)

cookie = ""

csrf_token = ""

for c in s.cookies:

if c.name == "jsessionid":

csrf_token = c.value

cookie = cookie + c.name + "=" + c.value + "; "

cookie_data =

with open("cookie.json", "w") as f:

f.write(str(cookie_data))

def test_login(self):

with open("cookie.json", "r") as f:

cookie_text = f.read()

json_cookie = demjson.decode(cookie_text)

csrf_token = json_cookie['csrf_token']

cookie = json_cookie['cookie']

headers1 = ',

'cookie': cookie,

'accept-encoding': "gzip, deflate, br",

'x-li-lang': "zh_cn",

'accept-language': "zh-cn,zh;q=0.9,en-us;q=0.8,en;q=0.7",

'x-li-page-instance': "urn:li:page:d_flagship3_feed;lvtq1iy2qegsohioa8jaqq==",

'csrf-token': csrf_token.replace('"', ""),

'x-restli-protocol-version': "2.0.0",

'authority': "www.linkedin.com",

'referer': "feed/",

'cache-control': "no-cache",

}url = "feed/"

response = requests.request("get", url, headers=headers1)

response.encoding = "utf-8"

print(response.text)

# u = "voyager/api/onboarding/launchpadcard"

# querystring =

# r = requests.get(u, headers=headers1, params=querystring)

# print(r.text)

if __name__ == "__main__":

login = login()

# login.get_index_csrf_and_cookie()

# login.login()

# with open("index_cookie.json", "r") as f:

# session = f.read()

# se = demjson.decode(session)

# print(se.get("csrf_token"))

## with open("cookie.json", "r") as f:

# cookie = f.read()

# json_cookie = demjson.decode(cookie)

# print(json_cookie['cookie'])

login.test_login()

c curl模擬登陸

我們在使用一些 時,輸入使用者名稱,密碼即可登陸該 登陸原理就是將使用者輸入的使用者名稱和密碼組合成乙個特定字串,post給乙個url位址,如果使用者名稱密碼正確,就可以登陸了,如果想使用程式模擬這種登陸過程,需要下面的步驟 1 抓包工具,推薦使用httpwatch專業版,輸入使用者名稱,密碼就開始...

CURL模擬登陸

created by phpstorm.user machenike date 2016 7 8 time 13 40 header content type text html charset utf 8 set time limit 0 關閉請求時間 cookie tempnam cookie ...

Python requests 模擬登陸

本段 是為了模擬登陸教務處系統,從而實現自動預約講座的準備。cookies raw cookies forline in raw cookies.split key,value line.split 1 1代表只分一次,得到兩個資料 cookies key value testurl s reque...