[Network security takes you to practice reptiles-100 exercises] Practice 9: Post submission/extraction of json data packets

Table of contents

1. Goal 1: post submits json data package

2. Goal 2: Receive json data packets

3. Goal 3: Extract the specified key value

4. Small circle of network security


1. Goal 1: post submits json data package

(You can find one by yourself, like refreshing some logged-in websites, basically there are)

 

data submitted by post

Put the json data to be submitted using post into data

        data = {
            '键名1':'键值1'
            '键名2':'键值2'
                }

Get the returned data of the request

        res = requests.post(url, data=data, headers=headers,timeout=10)


2. Goal 2: Receive json data packets

Get the returned json data

Turn it into text format, and print it

        if res.status == 200:
            json_data = json.loads(res.text)
            print(json_data)
        else:
            print('发包失败')

operation result:

Debugging found that it was a 403 status code (no access), and then jumped out

So there is no data and cannot be printed out

(I can't find a good data package, so let's do this first)

 



3. Goal 3: Extract the specified key value

 

Specify by adding ['key name']

        res = requests.post(url, data=data, headers=headers,timeout=10)
        json_data = json.loads(res.text)
        test1 = json_data['data']
        test2 = json_data['key_id']
        print(test1,test2)

If there are multiple [arrays] in the key name

We need to use [num] to choose which array to use

Extract content 1: ['xxx'][0]

Extract content 2: ['xxx'][1]

'xxx':[
内容1
]
[
内容2
]

Full code:

import requests
import json
from fake_useragent import UserAgent

def post_json():
    try:
        url = 'https://miao.baidu.com/abdr?_o=https%3A%2F%2Fquake.360.net'
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67',
            'Cookie': '!!!!'
        }

        data = {
            "data":"!!!!",
            "key_id":"!!!!",
            "enc":2
                }

        res = requests.post(url, data=data, headers=headers,timeout=10)
        json_data = json.loads(res.text)
        test1 = json_data['data']
        test2 = json_data['key_id']
        print(test1,test2)


        # if res.status == 200:
        #     json_data = json.loads(res.text)
        #     print(json_data)
        # else:
        #     print('发包失败')

    except:
        return ""


if __name__ == '__main__':
    post_json()



4. Small circle of network security

README.md Book Bansheng/Network Security Knowledge System-Practice Center-Code Cloud-Open Source China (gitee.com) https://gitee.com/shubansheng/Treasure_knowledge/blob/master/README.md

GitHub - BLACKxZONE/Treasure_knowledgehttps://github.com/BLACKxZONE/Treasure_knowledge

おすすめ

転載: blog.csdn.net/qq_53079406/article/details/131595290