Crawling Ctrip (Ajax dynamic loading)

Crawl Ctrip.com

‘content-type’:‘application/json’,

This request header parameter is the key

import requests
import json
import re

headers = {
    'USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'en',
    'referer': 'https://vacations.ctrip.com/',
    'content-type':'application/json',
    'origin': 'https://vacations.ctrip.com',
}

data = {"contentType": "json",
        "head": {"cid": "09031030111366754355", "ctok": "", "cver": "1.0", "lang": "01", "sid": "8888", "syscode": "09",
                 "auth": "", "extension": []}, "version": "80400",
        "client": {"trace": "none", "device": "PC", "source": "NVacationSearchV2",
                   "variables": [{"key": "SHXVERSION", "value": "B"}], "cid": "1605494184427.2ep3s2"},
        "poiType": {"poid": 1, "type": "D", "keyword": "北京"},
        "filtered": {"sort": 8, "channel": "Online", "tab": "A126", "saleCity": 206, "startCity": 206, "pageSize": 30,
                     "pageIndex": 2, "items": [{"key": "CHANNEL_ID", "value": "114"}]}, "returnType": {"type": "all",
                                                                                                       "filters": "ProductNewLine,ProductLine,HotDestination,HotScenicSpot,SaleDepartureStat,TravelDays,DepartureDate,Month,ProductPattern,ProductLevel,ADSuitPersons,ADServiceCharacteristic,ADIsDirectFlight,ADHotelCharacteristic,ADNLineCharacteristic,ProductDistrict,ProviderBrand,PriceRange,Promotion,OnSale,ADServiceGarantee",
                                                                                                       "recommendProduct": True}}

response = requests.post(
    'https://vacations.ctrip.com/list/restapi/gateway/13561/search?_fxpcqlniredt=09031030111366754355',
    data=json.dumps(data), headers=headers)
print(response.text)

Guess you like

Origin blog.csdn.net/weixin_46073538/article/details/110236315