爬取 携程
主页面urlhttp://flights.ctrip.com/booking/BJS-KMG-day-1.html?DDate1=2017-09-22
获取数据urlhttp://flights.ctrip.com/domesticsearch/search/SearchFirstRouteFlights?DCity1=BJS&ACity1=KMG&SearchType=S&DDate1=2017-09-22&IsNearAirportRecommond=0&LogToken=c802fde883e64a3c8fba0e99e45d023c&rk=2.7090996922689414192821&CK=1D7795E4EB96B7578AA673D6EF346C33&r=0.2337708871934405872019
首次搜索
http://flights.ctrip.com/domestic/Search/FirstRoute/?ddate1=2017-09-22&ddate2=2017-09-22&dcity1=BJS&acity1=KMG
http://flights.ctrip.com/domestic/booking/BJS-KMG---D-adu-1/?dayoffset=1&ddate1=2017-09-22&ddate2=2017-09-22
重新搜索
http://flights.ctrip.com/booking/bjs-kmg---d-adu-1/?ddate1=2017-09-22&ddate2=2017-09-22 往返
http://flights.ctrip.com/booking/BJS-KMG-day-1.html?DDate1=2017-09-22 单程
往返
var url = "//flights.ctrip.com/domesticsearch/search/SearchRoundRecommend?DCity1=BJS&ACity1=KMG&SearchType=D&DDate1=2017-09-22&ACity2=BJS&DDate2=2017-09-22&IsNearAirportRecommond=0&LogToken=3c10647ccad04412a33567f25335875a&CK=97017DBB47A37AFE6BE4D99105F78AFE";
单程
var url = "//flights.ctrip.com/domesticsearch/search/SearchFirstRouteFlights?DCity1=BJS&ACity1=KMG&SearchType=S&DDate1=2017-09-22&IsNearAirportRecommond=0&LogToken=66c9c383c12f4dc685a9ad3e5834a7c4&CK=D6BF57FFFC0A4E89AF51CF7186A1944E";
根据直接获取json的url拿到数据解析后就能获得航班信息,这个url里有4个参数,需要从搜索主页的页面里获取
单程和往返的原理一样,就是往返多了一个返回日期,其他都一样
LogToken不变 r不变 CK有变化 rk用Math.random
LogToken
rk
CK
r 在主页面的第34行
LogToken和CK根据主页面24行的url可以得到,r值在主页面34行可以得到
获取的json数据的url,爬取数据用的url
单程
http://flights.ctrip.com/domesticsearch/search/SearchFirstRouteFlights?DCity1=BJS&ACity1=KMG&SearchType=S&DDate1=2017-09-22&IsNearAirportRecommond=0&LogToken=c96a69a7ca9142be9f0e3192f44f9f07&rk=1.445840834132689163412&CK=6A53EEBD27EBBE6785AF7951EC03EB1E&r=0.3795051054613884121115
往返
http://flights.ctrip.com/domesticsearch/search/SearchFirstRouteFlights?DCity1=BJS&ACity1=KMG&SearchType=D&DDate1=2017-09-22&ACity2=BJS&DDate2=2017-09-22&IsNearAirportRecommond=0&LogToken=584465ec999045db9a546e1ce6a04a3f&rk=4.057381591787214165342&CK=D76BF5FFFC0A4E89AF51CF7186A1944E&r=0.543402675163338674414