第一步,正常分析页面,可以看到请求参数被加密了
第二步, 打断点查看加密方式。断点方式如下,在Sources 下面右侧的XHR,添加请求网址后几个字符串。添加完网址,清空cooKies后请求,按照图中步骤查看。注意,标注2 中蓝色箭头会默认在 callstack 下,也就是当时请求的位置。由此向下,是请求的上一步。(能力有限,懂得老铁都懂,不懂的可以参考其他人)
第三步,查看堆栈中对应每一步在文件中内容。可以看到有请求参数key
第四步,在console下进行测试,可以看到base64 编码
第五步,本地请求原字符串base64编码
第六步,上代码
# -*- coding:utf-8 -*-
# @Time : 2023/10/24 10:58
# @Author: 水兵没月
# @File : XXXX.py
# @Software: PyCharm
import base64
import random
import requests
from g import get_proxy # 代理
# "start":"10","end":"20" 翻页部分
info = '{"start":"10","end":"20","sourceId":"0902fd30eaf04a109c3601389e49ecf4","county":"5biC57qn","ApplicationID":"","ProjName":"","sort":" ACCEPTTIME desc"}'
data = {
"params": base64.b64encode(info.encode('utf-8'))
}
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Host": "sthjt.jiangsu.gov.cn",
"Pragma": "no-cache",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
}
url = 'http://XXXXXXXXX/eportal/admin?moduleId=f0270681ba5545089012be244338c858&struts.portlet.mode=view&struts.portlet.action=/portlet/commonSearch!getDataList.action'
res = requests.session().post(url, headers=headers, data=data , proxies=get_proxy()) # proxies=get_proxy(random.choice([4]))代理,没有可以裸爬
res.encoding='utf-8'
print(res.text)