關於post請求發送數組


網址: http://jzxxgk.jian.gov.cn/xxgk-list-xzsqfwzxsqchxc.html

ajax: http://jzxxgk.jian.gov.cn/api-ajax_list-3.html, 參數參考下面的函數

    function show_lists(page) {
        $.ajax({
            url: "api-ajax_list-" + page + ".html",
            type: "post",
            async: false,
            data: {
                "ajax_type": ["12_xxgk", "95446", 12, "xxgk", "Y-m-d", 22, 20, ["inputtime DESC"], "..."],
                "is_ds": 1
            },
            dataType: "JSON",
            success: function (data) {
            }
        })
    }

請求參數

抓取的請求參數

一般post請求把數據往表單中一放, 就可以了(文章中的url不需要設置header)

import requests


data = {
    "ajax_type": ["12_xxgk", "95446", 12, "xxgk", "Y-m-d", 22, 20, ["inputtime DESC"], "..."],
    "is_ds": 1
}

if __name__ == '__main__':
    url = 'http://jzxxgk.jian.gov.cn/api-ajax_list-3.html'
    res = requests.post(url=url, data=data)
    print(res.json())

然並卵, 並沒有出現想要的結果

{
    "status":0,
    "msg":"新聞或信息公開表不存在"
}

修改一下請求參數試試

import requests

datas = {
    "ajax_type[0]": "12_xxgk",
    "ajax_type[1]": "95464",
    "ajax_type[2]": 12,
    "ajax_type[3]": "xxgk",
    "ajax_type[4]": "Y-m-d",
    "ajax_type[5]": 22,
    "ajax_type[6]": 20,
    "ajax_type[7]": ["inputtime DESC"],
    "ajax_type[8]": "...",
    "is_ds": "1",
}

if __name__ == '__main__':
    url = 'http://jzxxgk.jian.gov.cn/api-ajax_list-3.html'
    res = requests.post(url=url, data=datas)
    print(res.text)

再看一下結果, 數據有點多, 就不全貼出來了

{
    "data":[
        {
            "id":"9956094",
            "catid":"95464",
            "title":"關於中心城區公園改造提升工程環境影響 報告表...",
            "slug_title":"",
            "sub_title":"",
            "outlink":null,
            "is_top":"0",
            "thumb":"",
            "keywords":"",
            "hits":"0",
            "uid":"1",
            "author":"admin",
            "status":"9",
            "url":"[http://jzxxgk.jian.gov.cn/xxgk-show-9956094.html](http://jzxxgk.jian.gov.cn/xxgk-show-9956094.html)",
            "link_id":"0",
            "tableid":"199",
            "inputip":"127.0.0.1",
            "inputtime":"2017-07-21",
            "updatetime":"1970-01-01",
            "comments":"0",
            "favorites":"0",
            "serial":"D3161-0503-2017-0042",
            "displayorder":"0",
            "laiyuan":"",
            "zuozhe":"",
            "ct_site":"",
            "dy_site":"",
            "bolds":null,
            "zt_css":"0",
            "ct_site_new":"",
            "dy_site_new":null,
            "wjbh":null,
            "gkfs":"主動公開",
            "gksx":"常年公開",
            "gkfw":"面向全社會",
            "zerenbumen":null,
            "ol":1
        },
       ...
    ],
    "total":233
}

原因

為啥用下標寫就可以了呢, 為了保持順序, 后台可能是通過下標來獲取信息的吧

正常請求

正常發送的請求參數

將參數拷貝到postman中再發送

將參數拷貝到postman中發送的請求

參數的順序發生了變化, 后台自然就獲取不到正確的值了, 也就不會有結果了

附加

下標為7的元素也是一個列表, 也是一樣的寫法

datas_2 = {
    "ajax_type[0]": "12_xxgk",
    "ajax_type[1]": "93745",
    "ajax_type[2]": 12,
    "ajax_type[3]": "xxgk",
    "ajax_type[4]": "Y-m-d",
    "ajax_type[5]": 22,
    "ajax_type[6]": 20,
    "ajax_type[7][0]": "is_top DESC",
    "ajax_type[7][2]": "displayorder DESC",
    "ajax_type[7][3]": "inputtime DESC",
    "ajax_type[8]": "...",
    "is_ds": "1",
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM