前面发的中国银行汇率的代码。增加了验证码以及第二页加密,并增加了token验证。以下是代码已逆向
前面发的汇率的代码。增加了验证码以及第二页加密,并增加了token验证。以下是代码已逆向
import time as _xo, requests as _ya, re as _zl, base64 as _mn, ddddocr as _dd _xe = _xo.sleep def _a1(_b2): _xe(1) _t4 = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0", } _c5 = _ya.get('https://srh.bankofchina.com/search/whpj/CaptchaServlet.jsp', headers=_t4) if _c5.status_code == 200: _d6 = _c5.text _e7 = _mn.b64decode(_d6) with open("t.png", "wb") as _f8: _f8.write(_e7) _g9 = _dd.DdddOcr(beta=True) _ha = open("t.png", "rb").read() _ia = _g9.classification(_ha) _jb = _c5.headers.get('Token') _kc = _xo.strftime('%Y.%m.%d ', _xo.localtime()) + '09:45:00' _ld = _xo.strptime(_kc, "%Y.%m.%d %H:%M:%S") _me = int(_xo.mktime(_ld)) _nf = _xo.strftime('%Y-%m-%d ', _xo.localtime()) _o1, _p2 = [], [] try: _qr = 'https://srh.bankofchina.com/search/whpj/search_cn.jsp' _rs = { 'erectDate': _nf, 'nothing': _nf, 'pjname': _b2, "head": "head_620.js", "bottom": "bottom_591.js", 'first': 1, "token": _jb, "captcha": _ia } _st = _ya.post(_qr, headers=_t4, data=_rs).text _tu = _zl.findall(r'<td>(.*?)</td>', _st, _zl.S)[1::] _uv = _zl.findall(r'"paramtk" value="(.*?)">', _st, _zl.S) _uv = _uv[0] if len(_uv) > 0 else '' _vw = [_tu[i:i + 7] for i in range(0, len(_tu), 7)] _o1.extend(_vw) for _wx in range(2, 16): _yz = { 'erectDate': _nf, 'nothing': _nf, 'pjname': _b2, 'page': _wx, "head": "head_620.js", "bottom": "bottom_591.js", "paramtk": _uv, "token": _jb, } _ab = _ya.post(_qr, headers=_t4, data=_yz).text _bc = _zl.findall(r'<td>(.*?)</td>', _ab, _zl.S)[1::] _cd = [_bc[i:i + 7] for i in range(0, len(_bc), 7)] if not _cd: break _o1.extend(_cd) _uv = _zl.findall(r'"paramtk" value="(.*?)">', _ab, _zl.S) _uv = _uv[0] if len(_uv) > 0 else '' _jb = _zl.findall(r'"token" value="(.*?)">', _ab, _zl.S) _jb = _jb[0] if len(_jb) > 0 else '' for _de in _o1: _ef = _de[-1].split('\r')[0] if _ef: _fg = _xo.strptime(_ef, "%Y.%m.%d %H:%M:%S") _gh = int(_xo.mktime(_fg)) if _me > _gh: _p2.append(_de) _xe(1) if _p2: _hi = { '美元': "USD", '欧元': "EUR", '加拿大元': "CAD", '印尼卢比': "IDR", '港币': "HKD", }.get(_b2, "CNY") _ij = float("{:.4f}".format(float(_p2[0][-2]) / 100)) _jk = _p2[0][-1].replace('\r\n', '').rstrip() return _ij, _jk, _hi else: raise ValueError("未找到符合条件的汇率数据") except Exception as _kl: raise _kl