python爬虫爬取携程国际机票航班信息,返回json串

阅读: 评论:0

python爬⾍爬取携程国际机票航班信息,返回json串
# -*- coding: utf-8 -*-
import requests, json
import hashlib
import re
# 此处的参数是json  出发三字码,达到三字码,出发时间,成⼈数,⼉童数,婴⼉数,三字码请传⼩写的
def get_index(paramter):
# 如果只执⾏这个脚本,需要将下边这⾏注释掉,如果放到服务,就打开
# paramter = json.loads(paramter)
dep_code = paramter["dep_code"]去方特的十大禁忌
arr_code = paramter["arr_code"]
date = paramter["date"]
adult = paramter["adult"]
child = paramter["child"]
infant = paramter["infant"]
urls ='ip/international/search/oneway-{}-{}?depdate={}&cabin=y_s&adult={}&child={}&infant={}'.format(
dep_code, arr_code, date, adult, child, infant)
# 这个url返回所需要的参数
# urls = 'ip/international/search/oneway-bjs-sel?depdate=2019-05-21&cabin=y_s&adult=1&child=0&infant=0'
headers ={
'headers':'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/72.0.3626.109 Safari/537.36' }
response = (urls, headers=headers)
data = re.findall(r'GlobalSearchCriteria =(.+);', )[0]
post_dict = json.loads(data)
return post_dict, date
def get_data(post_dicts):
post_dict = post_dicts[0]
date = post_dicts[1]
上海旅游攻略三日游
# ABTString = re.findall('id="ab_testing_tracker" value=(.+)/>', )[0]
trans_id = post_dict['transactionID']
url ="ip/international/search/api/search/batchSearch"
# 拼接加密参数 trans_id +出发地到达地+时间
sign_value = trans_id + post_dict['flightSegments'][0]['departureCityCode']+ post_dict['flightSegments'][0][
'arrivalCityCode']+ date
# 进⾏md5加密
md5 = hashlib.md5()
md5.update(de('utf-8'))
sign = md5.hexdigest()
flightWayEnum ="OW"
arrivalProvinceId = post_dict["flightSegments"][0]["arrivalProvinceId"]
arrivalCountryName = post_dict["flightSegments"][0]["arrivalCountryName"]
cabinEnum = post_dict["cabin"]
departCountryName = post_dict["flightSegments"][0]["departureCountryName"]
衡水旅游景点最好玩的地方segmentNo =len(post_dict["flightSegments"])
departureCityId = post_dict["flightSegments"][0]["departureCityId"]
isMultiplePassengerType =0
post_dict["flightWayEnum"]= flightWayEnum上海世博会展馆图片
post_dict["arrivalProvinceId"]= arrivalProvinceId
post_dict["arrivalCountryName"]= arrivalCountryName
post_dict["cabinEnum"]= cabinEnum
post_dict["departCountryName"]= departCountryName
post_dict["segmentNo"]= segmentNo
post_dict["departureCityId"]= departureCityId
post_dict["isMultiplePassengerType"]= isMultiplePassengerType
# payload = '{"flightWayEnum":"OW","arrivalProvinceId":0,"arrivalCountryName":"韩国","infantCount":0,"cabin":"Y_S","cabinEnum":"Y_S","departCountry天门山景区门票预订
# payload = '{"flightWayEnum":"OW","arrivalProvinceId":0,"arrivalCountryName":"韩国","infantCount":0,"cabin":"Y_S","cabinEnum":"Y_S","departCountry Name":"中国","flightSegments":[{"departureDate":"2019-05-21","arrivalProvinceId":0,"arrivalCountryName":"韩国","departureCityName":"北京","departureCit yCode":"BJS","departureCountryName":"中国","arrivalCityName":"⾸尔","arrivalCityCode":"SEL","departureCityTimeZone":480,"arrivalCountryId":42,"timeZo ne":480,"departureCityId":1,"departureCountryId":1,"arrivalCityTimeZone":540,"departureProvinceId":1,"arrivalCityId":274}],"childCount":0,"segmentNo":1," adultCount":1,"extensionAttributes":{},"transactionID":"c9ab78578e8342e8ba1101e5104fc5bd","directFlight":false,"departureCityId":1,"isMultiplePassenger Type":0,"flightWay":"S","arrivalCityId":274,"departProvinceId":1}'
# payload = de('UTF-8')
headers ={
'origin':"ip",
'sign': sign,
'user-agent':"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36",
'content-type':"application/json;charset=UTF-8",
'accept':"application/json",
'transactionid': trans_id,
'Host':"ip",
'content-length':"815",
'Connection':"keep-alive",
'cache-control':"no-cache"
}
response = quest("POST", url, data=json.dumps(post_dict), headers=headers)
# )
if __name__ =='__main__':清迈十大必去景点
para ={"dep_code":"bbk","arr_code":"bjs","date":"2019-10-25","adult":1,"child":2,"infant":1}
post_dicts = get_index(para)
print(get_data(post_dicts))

本文发布于:2023-07-21 01:05:51,感谢您对本站的认可!

本文链接:http://www.035400.com/whly/3/540135.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:上海   字码   放到   返回   参数
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2024-2030 Comsenz Inc.Powered by © 文化旅游网 滇ICP备2022007236号-403 联系QQ:1103060800网站地图