中国裁判文书网全网最新爬虫分析
本文主要介绍交流一下裁判文书网的爬去规则,我主要是因为公司要求而去分析这个网站的,一看是看该网站服务器各种卡,蛋疼。用python的selenium模块去写太麻烦了,做不到大量爬取,迫不得已自己不断研究,终于攻破了该网站的js代码参数

思路主要通过python去破解网站js的加密数据。该网站请求数据都是通过post请求的,分析一下header,会发现,它是一个post请求,请求的表单数据包括param、index、page、order、direction、vl5x、number、guid这几个参数。很显然,param是查询字符串,index是页码,page是一页展示的数据量,order是排序方式,其中,vl5x、number、guid是js代码加密生成得可变参数。一次性向对方服务器发送请求后获取相应得数据得。


现在最关键得是如何解密这三个参数?我主要用得是python得PyV8模块去调度js代码,列出代码中使用得python模块。

找一个浏览器里已经用过的vl5x去post ListContent,返回的是remind key,因此这个vl5x值是实时计算生成的。
到底这个值是怎么计算的呢,既然浏览器能算出vl5x的值,那算法应该隐藏在网页的JS文件中。好吧,继续找,在Lawyee.CPWSW.List.js文件里找到了这段代码:

vl5x的值是是用getKey()函数算出来的,而getKey里面传入得参数是你每次登陆网站,自动给你分配得动态cookies而产生得。


这样我们就可以得到vl5x动态参数。接下来就是比较麻烦得guid参数了,guid其实是一个动态的随机生成参数,附上python代码:

然后拿这个guid参数取请求该网站的getcode网址,拿到number参数。


这样我们三个参数同时拿到,一次性向服务器发送请求,获取数据

这样我们就可以直接获取大量的司法文书数据了,展示一下效果

大家可以有问题可以和我交流学习,这个技术分享出来,希望可以帮到更多的人。