網(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())
然并卵, 并沒(méi)有出現(xiàn)想要的結(jié)果
{
"status":0,
"msg":"新聞或信息公開(kāi)表不存在"
}
修改一下請(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)多, 就不全貼出來(lái)了
{
"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)公開(kāi)",
"gksx":"常年公開(kāi)",
"gkfw":"面向全社會(huì)",
"zerenbumen":null,
"ol":1
},
...
],
"total":233
}
原因
為啥用下標(biāo)寫(xiě)就可以了呢, 為了保持順序, 后臺(tái)可能是通過(guò)下標(biāo)來(lái)獲取信息的吧
正常請(qǐng)求
正常發(fā)送的請(qǐng)求參數(shù)
將參數(shù)拷貝到postman中再發(fā)送
抓取的請(qǐng)求參數(shù)
參數(shù)的順序發(fā)生了變化, 后臺(tái)自然就獲取不到正確的值了, 也就不會(huì)有結(jié)果了
附加
下標(biāo)為7的元素也是一個(gè)列表, 也是一樣的寫(xiě)法
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",
}