打印返回结果,并把结果复制到一个新建的.json文件中。通过pycharm的提示功能,找到以下错误。不知道这算不算一种注入。
找到浏览器抓的包,发现也有错误。如下图所示,预览不可解析,返回结果在网页搜索不到
正常返回值,应如下图,预览中可解析,网页可搜索:
import requests
import time
import json
timestamp = int(time.time()*1000)
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
}
url = "https://image.baidu.com/search/acjson"
for pn in range(30, 270, 30):
params = {
"tn": "resultjson_com",
"logid": "6988927784969315690",
"ipn": "rj",
"ct": "201326592",
"is": "",
"fp": "result",
"fr": "",
"word": "Python",
"queryWord": "Python",
"cl": "2",
"lm": "-1",
"ie": "utf-8",
"oe": "utf-8",
"adpicid": "",
"st": "-1",
"z": "",
"ic": "0",
"hd": "",
"latest": "",
"copyright": "",
"s": "",
"se": "",
"tab": "",
"width": "",
"height": "",
"face": "0",
"istype": "2",
"qc": "",
"nc": "1",
"expermode": "",
"nojc": "",
"isAsync": "",
"pn": str(pn),
"rn": "30",
"gsm": str(hex(pn))[2:],
timestamp: ""
}
response = requests.get(url, headers=headers, params=params)
response.encoding = response.apparent_encoding
print(response.url)
text = response.text.replace(r"\'s", '')
try:
data_list = response.json()['data']
for data in data_list:
try:
print(data['hoverURL'])
except:
None
except:
print(text)
经过替换后,如下图可以看到。原错误不存在,但依然报错了