携程网 机票
1.前言
本实例需要用到的Python包有requests、PrettyTable(用于打印展示成表格形式)
pip install requests
pip install prettytable
2.实例代码:
from prettytable import PrettyTable
import requests
import json
def flyapi(dcity, acity, date):
date = date[0:4] + '-' + date[4:6] + '-' + date[6:8]
headers = {
"User-Agent": "Mozilla/5.0 (windows NT 10.0; Win64; x64) APPleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
"content-Type": "application/json", # 声明文本类型为 json 格式,
'Cookie': '__DAYU_PP=fbffA7JMjfFQYEJvq3yV285fa84ef3bb; _abtest_userid=14f10ca5-5fe5-4b90-8994-a9a2a8289725; _ga=GA1.2.1823657567.1547218198; _RSG=jB4_phNRhw9fNvhoLy8_29; _RDG=28f1ebd8af073928c800c3c3726b485bce; _RGUID=9eab6d7a-f3fc-42ed-90bf-23c572af95