两者区别在于,content中间存的是字节码,而text中存的是Beautifulsoup根据猜测的编码方式将content内容编码成字符串。
resp.text返回的是Unicode型的数据。
resp.content返回的是bytes型也就是二进制的数据。
也就是说,如果你想取文本,可以通过r.text。
如果想取图片,文件,则可以通过r.content。
(resp.json()返回的是json格式数据)
r.text
{
"code" : "0",
"msg" : "成功",
"result" : {
"onlineProductInfoDTOList" : [ {
"onlineSkuId" : 300522129,
"outSkuId" : "300522129",
"skuName" : "99010 规格1/份",
"spuId" : "100508015"
} ]
},
"responseId" : "51c0cd72069b4879b8c184e7ff58c10f",
"success" : true
}
r.content
b'{\n "code" : "0",\n "msg" : "\xe6\x88\x90\xe5\x8a\x9f",\n "result" : {\n "onlineProductInfoDTOList" : [ {\n "onlineSkuId" : 300522129,\n "outSkuId" : "300522129",\n "skuName" : "99010 \xe8\xa7\x84\xe6\xa0\xbc1/\xe4\xbb\xbd",\n "spuId" : "100508015"\n } ]\n },\n "responseId" : "51c0cd72069b4879b8c184e7ff58c10f",\n "success" : true\n}'