JS 逆向解析爬虫
js 的base64 加密转成Python
1 import requests 2 import execjs 3 import json 4 import base64 5 import time 6 7 url='http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1007' 8 data={ 9 "tdate": "2022-04-13", 10 "market": "SZE" 11 } 12 headers={ 13 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36', 14 'mcode': base64.b64encode(str(int(time.time())).encode()).decode(), 15 'Referer': 'http://webapi.cninfo.com.cn/' 16 } 17 r = requests.post(url=url,headers=headers,data=json.dumps(data)) 18 print(r.text)
Python执行js
1 with open('spider_test.js','r',encoding='utf-8') as f: 2 result = f.read() 3 # print(result) 4 res = execjs.compile(result) 5 cc = res.call("xx")# xx 是js 的函数名
AES解密
1 import requests 2 from Crypto.Cipher import AES 3 import json 4 5 6 url = 'http://jzsc.mohurd.gov.cn/api/webApi/dataservice/query/comp/list?pg=3&pgsz=15&total=0' 7 headers = { 8 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.38' 9 } 10 response = requests.get(url, headers=headers).text 11 # print(response) # 加密数据 12 # response = '95780ba0943730051dccb5fe3918f9fe1b6f2130681f99d5620c5497aa480f13f32e8cc4b2f871a9a59a1d0117ce9456ce6b66396085eaa2822aa2ffc121eac1885d297bbd68dcda88cd8b0b29e282f9fd6b8392d52b817608665d8a565119f3346fb19449490842b923ec5781524595bc078b2c15e47473f15860e2ed45c9dbab5a750581a26fcb22b99228eb09b541e83ac3724f373a7512ac3827fa40354d1e9af350488194daf6b0317870a9a65dee320e0d4cb84708b25e383c02095c17f20d09fb39ab6e1a150c85818ecc2a31c384412859eff0026319094965cffffbc42c9495ee35f03b2440b8baac751927c38b616dc2042a64223fa6a72f1dc685fcbb38fd7cc47f1efbc9f5bd2c7490e58fbd36cf5a3b4be852fac87c6e682bb7d554b9990431e2d550d914754c6ac899fef97980084a6ba4bfda771be81ea11fd1542b6ffafe1439be2c94f74f6a83bfce6d2bc2e9dc1d86b84eeb85c2b8dda8846d65232148f9d88ac4a675d2049c1ac6efae1e4a5f4a106f0e627fb89199d9491303a792672832269e9a5cc208be00fbf1baf342262ebdbef5eaf3a50a52eeae2811f2813697018bf103df428dc0d496af435d2384b2198000add245d87233c3955695a6daa1bb4bc5a8657b2c9dfbf9f4067097df759f5724a5cb3a747a58509e2f22da6cbcdd29ba95dc555cd40cba6d0a2eced0b15ece067bc949dce784b2ceb06a61e9f7dc8943445da701c15fc7053f2c21ea1fc877e02280d22f913983c6f1dead091312c37aa90a5967b71b4c34dab24468bde5f747d8f44f8fd4b0fa493ff49b92441a7e1e8c256a6a18573baa1bf16f5093e36a7c9e282a3156dba776ea6a94794c9a034ae4f5e77761e49569d194d10703302476e7fd8e25ab4669f0c7a6c7d0e2680847d77ea5a585f7f60e7fcebb1ae791b8216bb25b644f5094157bd62c6aebf0a7faf173b2fde0da6f9ebb0dcab8a129c11b9f972445aee5297d38e0cc72d0b4d9c84c7e6b0ecf592d37998d04df8c52d5776c2741863b5fefd69302f176909b6bc065c4b81fc959a348368d250a03a86145f81950937ca83e3a765e6afd71d00c68faeca8d4d76f5ad762fc7d17fd05894857841bec355bb1d7f75db95c8e30dea58536ac6288fd3429ca9ab48d1eddb48631734ce2a574d79b93952fa2c9e9665c6337b35ea2309344cd22fe1b92dbd02051917d6c5edf1f2259c5f8a0cb3fbd00391c298f0461ba16a2300337d0b60b224bc6b796cedeb427cd07d97f17460d490bc3b112d2b8403026ff5ff5a70dde82cf210f22c3c206ca3bfe34cc137bedad0f1ae712d7168226a42fd22f9e17dede40654157e4c4756bd10292c7d0e2eefba36634309aeb24d3725802243e2003a68dac0a3b539eed0dca51f6f0d57a5c58a117fc56910d0e7319b05e0fc4a5137952e2f958636b584973da7dd61b63101e2d0cffe2b249c562b72b64fb6ca67ed0246bf0f9185fe22c87dc6d3c8374239dd4e70cdbc5ccacbd359dea203c021ac7d54998b2f1571d7f787a3ce1c4fda45037bd33be1ff9da883a556e2ef81ad2047d35a5065e73402e0e02231bcb3724445df198ad53112db4690091a98edea0fd194480b4193c2e9bb1cee1fb37654fce593cc88c59537003dd297be5d88834ec00595a4dda9fe44e14193482f1d212cf33ec58be3edfbecf7c7908bbf4c4b9beee5d0ef148e1bbdae9daea30beadcc6f5639a6f4eb57719fda5bc0e8766a52da34f17f2aa1a4b608fb6e53938d8e74d3b53aaeee663e1053e8444d44fb7a782d3b087155c9341559ada772299b988e859039435751592c25532090c0cc1a4445ba93ab3a1c9e8cd198251ed3ed76cc5091b83ead3cf1e11ceeeb0461e923c394a0a9f37220b9a5ed8e5f01b360eb6661a6456cde6a4497186567d4324d469277be217c03b84048ad272a3ea49b943f4c7c70487d060cd24cd9ea61032207c2a13c1384e0b5159d70d78d5e224401b5142ca2548ff2a13d1029a3b54dd68c7ac03d2c004c645ea586cdebf96267fffac4079305e37ab11e3af6bdff0e296ee4b5efdd00b48f44a91eb8475ddd6668a0b7548a7640229aeb650f76e02005b782a0a082175f256654aa8e0f3e3675726c9697978fd4ac35b6b64107e373cf80a9881152e62b2c1841292dbc40c41a7a36c8d353f2add2731415dcd81be8b3cdbfe26dec973a4e6edf2382992409db93aea8f354fbea21a21c54747ac540e752b5b13fee5f5d30277de7178eb998e31656b266c4de884a878251d6108ef36bfe8ec1020cbd469debe57478fb3af6d369a6e12499ba5ee436cef3f3089aa1710a0ddf84809875b5fb0cf1ee1aedbb25e0df0617f1ec2b6bea01ba4c9ab3c54b8cecc1b12f47bb10b64e5c733e88a41db29467387833535071e3566f6c69eacdfb2141fed9bac9babbc6571aa1c284d8814cbc18a2c9f31c5ec801f4dfd9f7798c6039d0e66a6c9115d8bf6fcfea430506d4a6e06751d826909e311f0aab8c992aecc840fa8014c8b340dcfb063837aff3aaae1678b135057bf32f879948f99dda769f85bf3776fab9cb43b75ff52ed3ca7353c6fa1563d45735369b6f4f94e9aae0b4ac261b82b694c7822209b3d887c1f2e4861779ef5252a355539a4b68b38242ff47814a6f713484ade34bcbffced4de4eb8d5808cd45860d1b8f631c8200dd14c311d259da042a143ce9f29c33d0b7d1a680658d58c9348310fe78fc51ced58968e87b93d66b4ca4f6713db2cbfc26620319e691deca42c4491b109e81a4bdbda4c0f55f612322ff4cdce089f3015650f11ac30b50082d0d695acc830579513e0701325f152e7825bad57feeacbfe37b5139b57fb7b05fa810da98bd682964d78601bea90b59c3a2449364dafcf2e359a5fe0e4128452bf93ee6926b6bdeedce37a37383610ffae1700db539f9c2255f27a5f0ab9736b6e0ef943cc579b6c3b2399f89f924b0fdab56827122607535b7365c1a8e11cb1cc7c61465bcecec575650197c8e50b2eabe8c4ef9882fccc79c2972ad78233342a3ce3d7b56b3be6314c819fee365e665c0e76e6ba29e1cb961d9c3a5e7414bf759c42f874caf2a52d82ebde9025d51c8d6364946ab2f3d507ed6f43038ec1aa5111ce3289e1c3d2650e8b71556abcfb08abee27c433c63c6fe55a37dc9bb40b24601c989b52dc2c0639afe4cb1ece076e2772afdb4e7e1789044f2149905fa20075f6ea970f9907b7791e9cc695dbb39004274779b36dfe99fb5cfea67fcff4c6cfb1f3e7e84f8a2249b8740d4617867c2c50618a6680b96f1db3262c48301ed4cf144819c4de3ca385d826ec46842a7268a2b952d8a5532ccf5ead165c28da4c005cf25bb38b804c97193333ad1c42c7bc4bb6a10c06a2fd9e88005715679d7e2ec173865d67aceda8395c8ffc2bfb16fb11025a03c311dc7a51306f2913ea14ad7cf9abbb1697540574b1ae5fb46ba4eb0ccab9dd2dc5b3d975ad132ab37b3bcb48d43b0668d160f29d21eaab862c9660609a91b684a5877683801a6b80c330cfc3d08c0265268ed9751b3f0b01cb6f1b4ec1bfff120cb547d59ddf1221f4f0a56cb1294e2c43ba22397553b14157b73675a14cca11d65dbf34253a5934f9c3ffaf8829ce19c4f1c5652b45cc0b3ab2e47a6767cfbdde54c342bf923f35d5f2e25f0382f978beb593a070f87dbf8d626aae6789dcd142fafba9eabc35f671b5b4cb2d0f761876b594678160694b125152d709e2a7d55eb76380ec1285df9255b137c6f810df4cb9447f24c7f15f483949287501a38b35010822c37e6c7cd110f14fd5acbb476903dd5701cb145c5a4ec434ec45c7e62aec6528e1c7eb419a6ea8209a34092cd28cd1801205095134684de551eac400ece5ed76e0bafe79a77500d0955057ba30984ff0ec22a8df27ab77ffaf3b22723df2e2d4fb7b907134e9d2ad056574d55fa30b00881c155eae37b264e92ecaa2ab1a05b5ddf82fb1073a623903bd05cc057f5029548f4dd270bb3f128cd973a608941096af8bf2eb114ed8afee8b37ab5f6091449fd3c740064aa2a941975309c387a6a8f265cde923032fbdfed31bc50b45ba76016e7552a5ae64db6699052a72dba9d3a2655876a981df267d6c16cdc1561316809c533da9137c2794d53a25e9df67cb6b3e446d79251e098d2687d7f9810a5180989b3a6c225e9733ab1ef03db8e285f16bc1bc2d9d593ae511baa5110b213fcc72404f0e3c6784a21e397c7c9346153fef68fbf34e72cea62c95d71731f44794e2e6aace889e71719c7688a53dc664986fc34f3b523ac0125cc2aaa970864d51420bf847fa7dae0179f46c03afa49b6cdedb4acd7b62974a50f7ca6821b343cc60c167d36f2d0d198b565bec9354b914e04fbe876a4bc646d210ab58d76af889cb0b9c4e94e4a3b4976cbb6fc0f01370931747bfc0e9bfdccc34d6736072d63b8f2587fb18db39ef012ec4184d113d76e2ad1695dceca521fee480f3eac0c3ed266f2885792ab3c5b50f223183ea90a9fd6c919d545478b0c592002189da8f129c8f8e894b3259e5e781a323bb2cd1af60607a92e5fc2a8fbbd515339debf83acc1288c40b45f8d7b439bdd0e82a3879133d1120d22ca6cb2d205c4df226079c9485989dc7333dfb0e4f52936bae9c190461e0e764dbfbef826c20997f8442e6260c074761afbe7435c31733b50c459b553152307823108687f8ced58e526dffd152f2055d70ffe287aa03628ad5ef3f1bef098b79b789d7ce08680113720b60b64e0c262024b02fc1393fa69194f0862c60a01bbf7a005d1120d88f00c7dd80a0bf4d9df48b156707f2afb4bc2373c42dc9d2107c9d7eafcd66d7e88caf2ded64c85f4b099aa4a5b87bc5e0e4bc78d4df227bb8b32373fd64242d14654274fedaa288ed56e2bec3c79dc572ecd2573712903a832b944d51c6726060132af10d0e5e7c3c828d0f8e986b15b02e060d3a8143a4a1da4fe0fdfd51bea38a1d86f05c95fa6d0333c9767fa3bf2d71cb809e69ff8476c7bcda1254d30472670c10b01208056897f8494a07f7cf3329741fa4a6c3727563dc9c8a28e4a4bcf49ad1c63a24cbbee2676c232458e93972253b6b4db6afec8e9f3f98c511e35b3295aaa96583c135b2a53b85c4c0b4db25b64b81c840b51297894b6dfd4c531be6dab241b19808a28205fb65b1d82b5cfcc9ce98052d22ade9c10953a6e500ca549833307dea3f078b5573b4be2140e8686c5ebb853564c7f871eba037896144f2bd67fb90026ab5d817b9d025edb60b795084bd7562a122a7e3d7fb77dae46034e4175b58b441f1a71439a2e69d6c27042df8a6b6bbc1033aa0fe8872477fcf4e3e528d6b1eca43a4915fe9564cf5f58eab2a66379856e57cc59f726db7ac4f7115a330817624d5558d7db65081288a88651650c52823fb2538a984384841a6d24b3860db1ca1bc6d862855d0e5e5f5ff6311d0fbb6644ae89404490ff2bb20e88909a17f73d0a9ffad50d12222cf676182f53a7272e32af823521cfb1323d122d1a49984f4a8e8848ba66e58a7c0271669659ec044486b8b740547ca012480f967cd2cc98e9d26d70361db34319e7f08307767b6f4814626e9b5cd41c70978615e10138074581ad7bc5a388a598e0d519473f5431cd5291a54a6a12d469ec76aab392e7403117d9482858e6a49cc7f88d4a32a963467a865b6a99b6555a4b92a1cdbfcd239cb1e2428fd39b3a4056494b394291561527f01e5c76a03bebc8f8fe2a93387106965f1ee46c95c2a37ebadae9dd1b9883bf9b78a9a3118ef6a0203b8f3111a31788d03772c8b15c7f805e172a63b931413097cfa11cd769767394c5287cf631a76d323e2c6d049043bbcc52884c8b0a7df8b6c02cf878bd51a6c5167570077484eaf4b12a7e8d4aaf72833bde4d8f774f276ad0c2f89ac104b856dc308c185e7f417c0d371ed34db32a5d627b7ac3ccd4d33f5007a627d13bcdb62a06434598422244c34dddc48b00c4453b2aa9099a1f4ec3ab5a3c31dc8aa600dcf74ddd7cf30429ea91b01b452afba639379881f532ae4d648220eb6552758dc47752b391d746922fbbd8cce200e305c5f2af90023a283bae8932edc0fef4c2b9b34b478ed02b5' 13 14 15 f = 'jo8j9wGw%6HbxfFn' # 秘钥 16 m = '0123456789ABCDEF' # 偏移值 17 18 # # 转码 utf-8? 字节 16进制 19 m = bytes(m, encoding='utf-8') 20 f = bytes(f, encoding='utf-8') 21 # print(m, f) 22 23 # # 创建一个AES算法 秘钥 模式 偏移值 24 cipher = AES.new(f, AES.MODE_CBC, m) 25 # # 解密 26 decrypt_content = cipher.decrypt(bytes.fromhex(response)) 27 result = str(decrypt_content, encoding='utf-8') 28 29 30 # PKCS7 填充 JavaScript 31 length = len(result) # 字符串长度 32 33 unpadding = ord(result[length - 1]) # 得到最后一个字符串的ASCII 34 result = result[0:length - unpadding] 35 36 result = json.loads(result)['data']['list'] # dupms json.dumps() dict 格式 json的 37 # # {"键":"值"} 38 39 for i in result: 40 print(i)