其他分享
首页 > 其他分享> > pytho接口自动化-session

pytho接口自动化-session

作者:互联网

1.参考代码

import requests
import json
import warnings
warnings.filterwarnings('ignore')


def getHeaders():
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) '
                     'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'

        }
    return headers


def getData():
    dict1 = {'formhash': 'b4ba6e',
             'txt_account': '13484545195',
             'pwd_password': '60e52c87966078c0b3fab7debb0fc892',
             'login_type': 3,
             'ckb_cookie': 0,
             'hdn_refer': 'http://www.epwk.com/',
             'txt_code': '',
             'pre': 'login',
             'inajax': '1'
             }
    return dict1


def login():
    r = requests.post(
        url='https://www.epwk.com/index.php?do=login',
        data=getData(),
        headers=getHeaders(),
        verify=False
    )
    return r.cookies


def employer():
    r = requests.post(
        url='http://i.epwk.com/home/employer/index.html',
        data={'model': 'xsrw', 'status': 'all'},
        headers=getHeaders(),
        cookies=login(),
        verify=False
        )
    print(r.text)


if __name__ == '__main__':
    employer()

 

标签:__,www,pytho,接口,getHeaders,headers,session,login,def
来源: https://www.cnblogs.com/yuer02/p/14649845.html