python interface to automate --token, cookies acquisition and transfer

  uniquely identifies the user token is generated after logging nearly all interfaces required to access token

  So I said what about the process of token

  First, define a login request method

  import requests

  def login():

  url = "http://test.xxxxxxx.com/api/common/login/login"

  data = {

  "phone":"1772xxxxxxx,

  "password":123456

  }

  h = {

  "User-Agent": "Android/H60-L01/8.1.0/"

  }

  res = requests.post(url, data=data, headers=h)

  print(res.json())

  login()

  Look at the return data

  Return data to show good part

  { 'Status': 1, 'msg': 'login success', 'data': { 'id': 6335, 'nickname': 'mimi', 'phone': '1772xxxxxx', 'token': '3143de184efaa49581cd1966ed2ef1a1' ,

  As can be seen the data is returned in the token dictionary data format can be used in the manner of the dictionary word extraction token values

  Extracted token and returns it

  return ( res.json()['data']['token'])

  Which is then sent down headers in a request

  def get():

  print({'token':login()})

  url = 'http://test.xxxxxxxxx.com/api/common/user/sign'

  h = {

  "User-Agent": "Android/H60-L01/8.1.0/",

  'token':login()

  } Wuxi abortion how much money http://www.bhnnk120.com/

  res = requests.post(url,headers=h)

  print(res.text)

  that's it

  acquisition and transfer cookies

  Log in to see the interface with print (r.cookies) to print cookies if you can get to

  import requests

  def login():

  data = {

  "phone":189xxxxxxxxxx,

  "password":123456

  }

  headers = {

  "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",

  "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",

  "Referer":"https://test.xxxxxxx.com/index/index/login/login.html"

  }

  r = requests.post(

  url='https://test.xxxxxxxx.com/index/index/login/login',

  date = time

  headers=headers)

  print( r.cookies)

  Cookies successfully print out the value

  And then return with the return

  return r.cookies

  In the same token the next request headers similar to splicing it


Guess you like

Origin blog.51cto.com/14335413/2435431