關(guān)于post請(qǐng)求發(fā)送數(shù)組

網(wǎng)址: http://jzxxgk.jian.gov.cn/xxgk-list-xzsqfwzxsqchxc.html

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

    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) {
            }
        })
    }

請(qǐng)求參數(shù)

抓取的請(qǐng)求參數(shù)

一般post請(qǐng)求把數(shù)據(jù)往表單中一放, 就可以了(文章中的url不需要設(shè)置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())

然并卵, 并沒有出現(xiàn)想要的結(jié)果

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

修改一下請(qǐng)求參數(shù)試試

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)

再看一下結(jié)果, 數(shù)據(jù)有點(diǎn)多, 就不全貼出來了

{
    "data":[
        {
            "id":"9956094",
            "catid":"95464",
            "title":"關(guān)于中心城區(qū)公園改造提升工程環(huán)境影響 報(bào)告表...",
            "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":"主動(dòng)公開",
            "gksx":"常年公開",
            "gkfw":"面向全社會(huì)",
            "zerenbumen":null,
            "ol":1
        },
       ...
    ],
    "total":233
}

原因

為啥用下標(biāo)寫就可以了呢, 為了保持順序, 后臺(tái)可能是通過下標(biāo)來獲取信息的吧

正常請(qǐng)求

正常發(fā)送的請(qǐng)求參數(shù)

將參數(shù)拷貝到postman中再發(fā)送

抓取的請(qǐng)求參數(shù)

參數(shù)的順序發(fā)生了變化, 后臺(tái)自然就獲取不到正確的值了, 也就不會(huì)有結(jié)果了

附加

下標(biāo)為7的元素也是一個(gè)列表, 也是一樣的寫法

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",
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容