爬虫POST请求Json格式不清楚报错原因
#coding:utf-8import requests
import json
result = {}
url1 = "http://222.134.9.172:8080"
postreq = "/ajaxpro/Com.BC863.Web.ClassifySearch,App_Web_classifysearch.aspx.cdcab7d2.ashx "
url = url1 + postreq
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",
}
payload='{"page":1 ,"isrig":false,"key": "bkname", "word": "1"}'
resp1 = requests.post(url,data=json.dumps(payload),headers=headers)
print(resp1.json())
提示信息:
Traceback (most recent call last):
File "C:\Users\二农戏猪\Desktop\1.py", line 21, in <module>
print(resp1.json())
File "D:\python\lib\site-packages\requests\models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "D:\python\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "D:\python\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\python\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
是我的json格式不对嘛 这是内网网址?? 说说你想干嘛吧
你的网址 我输入到浏览器 得到的是这个东东 啥东东看不懂的东东
if(typeof Com == "undefined") Com={};
if(typeof Com.BC863 == "undefined") Com.BC863={};
if(typeof Com.BC863.Web == "undefined") Com.BC863.Web={};
Com.BC863.Web.ClassifySearch_class = function() {};
Object.extend(Com.BC863.Web.ClassifySearch_class.prototype, Object.extend(new AjaxPro.AjaxClass(), {
BookBand: function(page, isrig, key, word) {
return this.invoke("BookBand", {"page":page, "isrig":isrig, "key":key, "word":word}, this.BookBand.getArguments().slice(4));
},
SearchByZhongTu: function(page, nodeid, isrig, key, word) {
return this.invoke("SearchByZhongTu", {"page":page, "nodeid":nodeid, "isrig":isrig, "key":key, "word":word}, this.SearchByZhongTu.getArguments().slice(5));
},
SearchByPlace: function(page, placeid, isrig, key, word) {
return this.invoke("SearchByPlace", {"page":page, "placeid":placeid, "isrig":isrig, "key":key, "word":word}, this.SearchByPlace.getArguments().slice(5));
},
SearchByClass: function(page, dcglid, isrig, key, word) {
return this.invoke("SearchByClass", {"page":page, "dcglid":dcglid, "isrig":isrig, "key":key, "word":word}, this.SearchByClass.getArguments().slice(5));
},
url: '/ajaxpro/Com.BC863.Web.ClassifySearch,App_Web_classifysearch.aspx.cdcab7d2.ashx'
}));
Com.BC863.Web.ClassifySearch = new Com.BC863.Web.ClassifySearch_class();
wp231957 发表于 2021-1-5 09:16
说说你想干嘛吧
你的网址 我输入到浏览器 得到的是这个东东 啥东东看不懂的东东
它的post请求包是一个json格式的
POST /ajaxpro/Com.BC863.Web.ClassifySearch,App_Web_classifysearch.aspx.cdcab7d2.ashx
host:http://222.134.9.172:8080
{"page":1 ,"isrig":false,"key": "bkname", "word": "1"}
大概就是一个这样的数据包 1.URL 多一个空格,访问的时候提示资源不存在。
2.去掉URL里的空格后,访问成功,但是response内容为空,估计你得核实一下参数或URL,或者服务器端的设置。
suchocolate 发表于 2021-1-5 12:17
1.URL 多一个空格,访问的时候提示资源不存在。
2.去掉URL里的空格后,访问成功,但是response内容为空 ...
POST /ajaxpro/Com. BC863. Web. Classi fySearch, App_ Web_ _classi fysearch. aspx. cdcab7d2. ashx HTTP/1. 1
Host: 123. 178. 167. 102:8000
User- -Agent: Mozilla/5. 0 (Windows NT 6.3; Win64; x64; rv:84. 0) Gecko/20100101 Firefox/84. 0
Accept: */*
Accept -Language: zh-CN, zh;q=0. 8, zh-TW;q=0. 7, zh-HK;q=0. 5, en-US;q=0. 3, en;q=0. 2
Content- Type: text/plain; charset=utf-8
X-AjaxPro-Method: BookBand
Content Length: 50
Connection: close
{”page" :1,”isrig" :false, "key":’bkname*", "word" :"1"}
这是那个请求包 二农戏猪` 发表于 2021-1-5 12:29
POST /ajaxpro/Com. BC863. Web. Classi fySearch, App_ Web_ _classi fysearch. aspx. cdcab7d2. ashx H ...
请求包是请求包,response是response,这个网站及时提交了data也没有response。 本帖最后由 YunGuo 于 2021-1-5 18:29 编辑
少了必须参数,还有传参错误,这样写就行了。
import requests
import json
url = 'http://222.134.9.172:8080/ajaxpro/Com.BC863.Web.ClassifySearch,App_Web_classifysearch.aspx.cdcab7d2.ashx'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
'X-AjaxPro-Method': 'BookBand'
}
data = {
'page': 1,
'isrig': False,
'key': '',
'word': ''
}
res = requests.post(url, headers=headers, data=json.dumps(data))
print(res.json())
页:
[1]