网页爬虫 - python爬虫爬取携程网的酒店评论数据时,有个请求参数不知道是怎么生成的?
阿神
阿神 2017-04-18 09:24:53
0
4
997

比如这个酒店:http://hotels.ctrip.com/hotel/dianping/1943326.html
酒店的点评数据是通过ajax方式异步加载的,不想用模拟浏览器的方式来爬,太慢了,想直接请求点评数据的地址,但是这个eleven参数不知道是怎么生成的,在网页源码中没找到,分析js代码也没看出个所以然来,请大神来分析下,多谢了

阿神
阿神

闭关修行中......

reply all(4)
迷茫

This is indeed a bit perverted, but you can simulate mobile phone access (change user agent). You can get comment data, which is static html.
http://m.ctrip.com/html5/hotel/HotelDetail/dianping/1943326.html
Look at the request carefully, there is a compressed js that is calculating parameters, it gives me a headache.

迷茫

Don’t worry about how it is generated, be more violent, bring all the headers, and all the parameters are the same, it must be OK

伊谢尔伦

It looks like it may be base64 encoded or encrypted. Related to other parameters, it is suspected that it is a signature parameter to prevent grabbing.

左手右手慢动作

is generated by the following code, which I can’t understand:
,_getElevenValue:function(e){

function o(e){
    for(var o=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],n="",t=0;e>t;t++){
        var i=Math.ceil(25*Math.random());
        n+=o[i]
    }
    return n
}
    
var n,t=o(7),i=!1;
if(!hotelDomesticConfig.cas.OceanBall)return e.resolve("");
for(;window[t];)
  t=o(15);
n=hotelDomesticConfig.cas.OceanBallUrl+"?callback="+t+"&_="+(new Date).getTime()
 ,window[t]=function(o){
                   window[t]=void 0;
                   var n="";
                   try{n=o()}
                   catch(a){$.ajax("/domestic/cas/image/bi"
                       ,{method:$.AJAX_METHOD_POST,cache:!1,context:{value:"11-"+encodeURIComponent(a.stack||a)}})
                   }
                   finally{i=!0,e.resolve(n)}
 }
 ,$.loader.js(n,{onload:function(){i||(window[t]=void 0,e.reject(""))},onerror:function(o){o&&(window[t]=void 0),e.reject("")}})

}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!