介面自動化之requests學習(三)--傳送post請求
阿新 • • 發佈:2018-12-15
想要用requests方法呼叫post請求,首先我們要有一個post介面,我們選擇人人網登入介面來練習
1.開啟人人網的登入頁面,獲取登入的url及傳送的引數
2.獲取到登入介面url及引數後,編寫程式碼
#!usr/bin/env python #-*- coding:utf-8 -*- """ @author:Administrator @file: requests_post.py @time: 2018/10/13 """ import requests import json data = {"email":"1989898932", 'icode':'', 'origURL':'http://www.renren.com/home', 'domain':'renren.com', 'key_id':'1', 'captcha_type':'web_login', 'password':'123123123', 'rkey':'6ed188b87746f002b04dcd3eb653fa63', 'f':'https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D30kal6ydyFtWVWEO6tqsyb4LlS-YlX4yH6U_26Wo9mW%26wd%3D%26eqid%3Dc12a001f00063a3c000000035bc1d85b' } url = "http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2018961914878" r = requests.post(url=url,data=data) #r.text返回的是字串格式 print(r.text) #r.json列印的是字典格式 print(r.json()) print(type(r.json())) #獲取錯誤提示資訊 dict1 = r.json() print(dict1["failDescription"])