问题描述:
今天碰到这个情况,还是记录下
这种分几种情况, 一种为 : json , 一种为:text
问题解决:
话不多说,直接上
requests 写法:
url = 'https://ggzy.yibin.gov.cn/TrueLoreAjax/TrueLore.Web.WebUI.AjaxHelper,TrueLore.Web.WebUI.ashx'
# data = '["TrueLore.Web.WebUI.WebAjaxService","GetPageZhongBiaoJieGuoGongShi",[0,15,"121",1,true,"zhaoBiao_XiangMu_Name","","OrderType "],null,null]1677745826283'
data = '["TrueLore.Web.WebUI.WebAjaxService","GetPageKBJL",[0,15,"112",1,false,"zhaoBiao_XiangMu_Name","","FBSJ DESC"],null,null]'
headers = {
"Ajax-method": "AjaxMethodFactory",
}
response = requests.post(url, data=data, headers=headers)
print(response.text)
txt = response.text
demo = txt.replace('\\r\\n', '').replace('\\', '').replace('"{', '{').replace('}"', '}')
print(demo)
print(type(demo))
print(json.loads(demo))
print(type(json.loads(demo)))
直接写成data就可以了 , 用字段串 包起来;
scrapy 写法:
data = r'["TrueLore.Web.WebUI.WebAjaxService","GetPageKBJL",[0,15,"112",1,false,"zhaoBiao_XiangMu_Name","","FBSJ DESC"],null,null]'
yield scrapy.Request(
url,
method='POST',
callback=self.parse,
body=data
)
因为不是json数据,是text的, 直接放在body里面 就可以了
具体的其他理论的,可以参考这个文章:https://blog.csdn.net/qq_38044574/article/details/83339439;