aHR0cHM6Ly9rZC5uc2ZjLmNuL2ZpbmFsUHJvamVjdEluaXQ=
注意:本文是逆向部分比较少,主要为了流程走通,限于代码搬运工。
第一步:分析页面
此网站经过请求响应,可以看出响应内容为加密内容。
第二步:判断加密类型
在XHR 处添加 请求段,清空cookie重新请求。可以看出在send 形成断点,开始进行调试。
经过调试可以看出,从请求到页面呈现数据,经过原始数据解密过程(网站及其不稳定,tlj),可以看出加密方式为DES-ECB,pkcs7,因此可以在此处进行断点。原断点可以去除,重新请求。
第三步:重新调试请求
在第二步确定断点后,重新请求,可以看出再断点处可以将密文进行解密。后续一步一步调试即可获取页面解析后数据。但根据下图可以知道是DES加密的因此,直接网上找相关js或者Python 对应方法即可。(我就没有再继续调试了,哈哈哈哈)
第四步: 下载图片进行OCR识别
获取详情页中,在线PDF中内容,且需要下载图片进行OCR识别
第五步:上代码(建议模块化)
# -*- coding:utf-8 -*-
# @Time : 2024/5/22 17:12
# @Author: 水兵没月
# @File : 某网站.py
# @Software: PyCharm
import json
from urllib import parse
from urllib.parse import urljoinimport execjs
import requests
import pytesseract
from PIL import Image
from a import get_proxy # 没有代理可以忽略
import base64
from Crypto.Cipher import DES
from Crypto.Util.Padding import unpad
import jsons = requests.session()
def req_payload(s, url, headers, data):res = s.post(url=url, data=json.dumps(data), verify=False, headers=headers)return resdef req_post(s, url, headers, data):res = s.post(url=url, data=data, headers=headers, verify=False) # impersonate="chrome101",return resdef req_get(s, url, headers):res = s.get(url=url, headers=headers, verify=False) # impersonate="chrome101",return resdef save_img(res, _id):with open("./某网站_img/{}.jpg".format(_id), "wb") as f:for chunk in res.iter_content(chunk_size=1024):if chunk:f.write(chunk)f.close()def OCR_shibie(path):# 指定 tesseract.exe 的安装路径pytesseract.pytesseract.tesseract_cmd = r'D:\Program Files\Tesseract-OCR\tesseract.exe'# 打开图片image = Image.open('./某网站_img/{}.jpg'.format(path))# OCR 识别text = pytesseract.image_to_string(image, lang='chi_sim')return textdef DES_ECB_Pkck(data, keys):# data = b"{}".__format__(data)des = DES.new(key=keys.encode("utf-8"), mode=DES.MODE_ECB)r = des.decrypt(base64.b64decode(data))r = unpad(r, DES.block_size).decode("utf-8")return rfuzzyKeyword = "XXXXX大学"
conclusionYear = "近五年"
pageNum = 1
data = {"complete": True, "fuzzyKeyword": fuzzyKeyword, "isFuzzySearch": True, "conclusionYear": conclusionYear, "dependUnit": "","keywords": "", "pageNum": pageNum, "pageSize": 10, "projectType": "", "projectTypeName": "", "code": "","ratifyYear": "", "order": "enddate", "ordering": "desc", "codeScreening": "", "dependUnitScreening": "","keywordsScreening": "", "projectTypeNameScreening": ""}
headers = {"Accept": "application/json, text/plain, */*","Content-Type": "application/json;charset=UTF-8","Referer": parse.quote("https://XXXX.XXX.XXX/finalSearchList?s={}".format(fuzzyKeyword)),"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",}
url = "https://XXXX.XXX.XXX/api/baseQuery/completionQueryResultsData"
res = req_payload(s, url, headers, data)
res.encoding = 'UTF-8'
text = res.text
# text = "BFjkDmNuMwgFUO1tnEEKp/jGSSR/i+e3W1IOLuJIBsiuC3rk6VGzPq4RWnnz5YLOzKirU1apUInNC1zjjDy4k3dA1znTXT7iKdTKBfP4n54y0hRbTwxWvFB/gL0sOehxKLY28E0Lk9UdJuIJyS0zCAzWzCk47s3+PXldk5lEezl+c55xohNdHj0+A4hc223IEaoceKzaAxWmeLZgxUTBVTN5GL6YpjW2YcAVyyNP/DzoSICPNuZlm52XKya/lFffmK8QpO6jVpCWKZhbR7Go7HI06qVGQYaFDCWpFkgrq8HmJVSHvhPEC6Hy4YP95b7IQLoqcMqjiUGOwH/EBnH3vUQL2NpbCyoAHLd0dqEWdEi1q2r+4sVVk3/975eUTwBRPT4DiFzbbchXDw2C+0fjo9eCCWwMbJvYg67lv6X0ckodF8VNWp09XBMrhd9f2HabffKb5dhF8pNRe52whNbpmbFrZ4852MnANj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Qbh6+KuBGNBb5Y+Zego/UzAzA+ejTEkrGrPIsSunD9ypeNTmipqrhVxGq64U/P38H3RUVgVd1mYOSAA9sN2n3p677OLIod7ZnsdCKiM+hTBPYubDHoKUxjJim4MhYJusWLhkORmZPa4zibikGcPYMVjFOUVdVCRG9z75ez47BDM+cFgrYHVHNJLOEMjWrTScepJWSNPnBlUBpbrs+xh6lVStJmyRAYCh8JOTA2WVsYQjnmXwudZj1ENtPZIFOTndwkKyE8Zi1XfIdgMU4TTaJtUialZuy2/G5Fp9NG+WheE5FrO7qHzgU51zyLErpw/cqVQJiB+7LwdczY1ib/crOv24xZj5I+e66VDxYnPlRRr8R2Ovt8d35hnip0TOYs0ZOoE4RgOeQWv0ysaLmR/Ne495JNsom9gP7NOIce5JZ9/jCweTjGMMCmEdG+Mn+Mk8fullp1akkbLzwk75vYzxr3/fJjVIPb47z3q8VGsnKMslhVZhAdUpRsrrMpT/87f8OtomvlKm1NoYyMjM2Elo71M"
if "访问" not in text:text_data = DES_ECB_Pkck(text,'IFROMC86')try:data = json.loads(text_data)except:data = {}data = data.get('data',{})resultsData = data.get('resultsData',[])for rd_list in resultsData[:2]:if not rd_list: continue_id = rd_list[0]print(_id)pdf_url = "https://XXXX.XXX.XXX/api/baseQuery/completeProjectReport" pdf_data = {"id":_id, "index":"1"}pdf_headers = {"Accept": "application/json, text/plain, */*","Authorization": "Bearer undefined","Content-Type": "application/x-www-form-urlencoded","Referer": parse.quote("https://XXXX.XXX.XXX/finalDetails?id={}".format(_id)),"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",}pdf_res = req_post(s, pdf_url, pdf_headers, pdf_data).json()img_url = pdf_res.get('data',{}).get('url','')if img_url:img_url = urljoin(pdf_url, img_url)img_res = req_get(s, img_url, pdf_headers)save_img(img_res, _id)ocr_res = OCR_shibie(_id)print(_id)print(ocr_res)