抓取网站数据的时候遇到一段打乱的JS怎么处理
0 条评论问题:
写app的时候,需要抓取一个页面的内容,但是这个页面的内容是通过js加载的,这段js是打乱的,直接分析有一定的难度
实现方式:通过eval直接执行拿到运行结果
这段js是这样的
1 | eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])} }return p}('d b=["3://1.0.2/6/5-4/e","3://1.0.2/6/5-4/9","3://1.0.2/6/5-4/7","3://1.0.2/6/5-4/a","3://1.0.2/6/5-4/8","3://1.0.2/6/5-4/c","3://1.0.2/6/5-4/m","3://1.0.2/6/5-4/k","3://1.0.2/6/5-4/l","3://1.0.2/6/5-4/f","3://1.0.2/6/5-4/i","3://1.0.2/6/5-4/g","3://1.0.2/6/5-4/h","3://1.0.2/6/5-4/j"]',23,23,'pstatp|p|com|https|image|pgc|origin|d5891339b36247969d42a7fd7a836f9f|f6c972d4636c491c81b8958fe911288e|556735adf1a24f81841c28c91bfc5cae|df9dac499fee4563a0aefb03bac3fa4c|newImgs|445c5485c19148728b9c04c31096cc04|var|789b3e348ea047ad87c53a6c8c41fa33|4b850a13dc4142199ba9f1d0c8f8b051|634908f1de0d44848be4b1c26c3897d8|25d2e2148e204590a32b5527d5a257b8|5fb7dd3e10ac418097245f80cc5ab349|5f812b16da9946e0b5446fbb00bd125f|ebe5f1137cea4f478160976df7fcf85c|c62a58b50a5740a1ab33b1e1fb9e8771|4cc33ea7b88945d6aaaac004b887750d'.split('|'),0,{})) |
方法
抓取到的内容是一段字符串,需要截取获得 function, 然后通过 eval 执行, 直接拿到 js 的运行结果
1 | const str = 'eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])} }return p}('d b=["3://1.0.2/6/5-4/e","3://1.0.2/6/5-4/9","3://1.0.2/6/5-4/7","3://1.0.2/6/5-4/a","3://1.0.2/6/5-4/8","3://1.0.2/6/5-4/c","3://1.0.2/6/5-4/m","3://1.0.2/6/5-4/k","3://1.0.2/6/5-4/l","3://1.0.2/6/5-4/f","3://1.0.2/6/5-4/i","3://1.0.2/6/5-4/g","3://1.0.2/6/5-4/h","3://1.0.2/6/5-4/j"]',23,23,'pstatp|p|com|https|image|pgc|origin|d5891339b36247969d42a7fd7a836f9f|f6c972d4636c491c81b8958fe911288e|556735adf1a24f81841c28c91bfc5cae|df9dac499fee4563a0aefb03bac3fa4c|newImgs|445c5485c19148728b9c04c31096cc04|var|789b3e348ea047ad87c53a6c8c41fa33|4b850a13dc4142199ba9f1d0c8f8b051|634908f1de0d44848be4b1c26c3897d8|25d2e2148e204590a32b5527d5a257b8|5fb7dd3e10ac418097245f80cc5ab349|5f812b16da9946e0b5446fbb00bd125f|ebe5f1137cea4f478160976df7fcf85c|c62a58b50a5740a1ab33b1e1fb9e8771|4cc33ea7b88945d6aaaac004b887750d'.split('|'),0,{}))' |
- 本文链接:https://xuehuayu.cn/article/25734.html
- 版权声明:① 标为原创的文章为博主原创,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接。② 标为转载的文章来自网络,已标明出处,侵删。