普通方式12306查票
import json
import requests
def ticket_checking():
url = 'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2021-06-05&leftTicketDTO.from_station=BJP&leftTicketDTO.to_station=SHH&purpose_codes=ADULT'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',
'Cookie': '_uab_collina=162286458314322450377165; JSESSIONID=F19E4CABF0446E168D6FA50C4CB87A28; BIGipServerotn=4057399562.64545.0000; BIGipServerpassport=837288202.50215.0000; RAIL_EXPIRATION=1623160466085; RAIL_DEVICEID=Q6gzZjoudUOX9zK7gEyEG7ukgCdfXm1U9VjOGA5pnMu64NdJT4sF007MAUP42q9chyI7f61jfW-4qaYsn7_2GR97tHR55f6YpxDsPw1nN6uR2N2mnkJ607nhXu-I902HqEX0YCK4ATiixksIMnNi8EWgZk1Uxi_w; route=6f50b51faa11b987e576cdb301e545c4; _jc_save_fromStation=%u5317%u4EAC%2CBJP; _jc_save_toStation=%u4E0A%u6D77%2CSHH; _jc_save_fromDate=2021-06-05; _jc_save_toDate=2021-06-05; _jc_save_wfdc_flag=dc'
}
req = requests.get(url, headers=headers)
return req.json()["data"]["result"]
for i in ticket_checking():
lst = i.split(sep='|')
print(f'{lst[3]}有商务特等座{lst[32]}个')
正则表达式
点此链接查看