Home  >  Q&A  >  body text

网页爬虫 - python爬虫爬取携程网的酒店评论数据时,有个请求参数不知道是怎么生成的?

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

阿神阿神2742 days ago1001

reply all(4)I'll reply

  • 迷茫

    迷茫2017-04-18 09:26:53

    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.

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:26:53

    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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:26:53

    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.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:26:53

    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("")}})

    }

    reply
    0
  • Cancelreply