码迷,mamicode.com
首页 > 其他好文 > 详细

獲取12306所需剩餘的票

时间:2019-03-08 23:30:50      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:三方   rom   url   res   date   result   imp   div   on()   

1、登陸官網,找到所需票頁面:

 

技术图片

 

2、按F12然後點擊查詢:

技术图片

 

3、先安裝requests 第三方庫:

  #pip install requests

4、寫入以下代碼:

 1 #!/usr/bin/env python3
 2 # -*- coding: UTF-8 -*-
 3 
 4 import requests
 5 
 6 #獲取12306官網的數據url
 7 def pacong():
 8     reque = requests.get(https://kyfw.12306.cn/otn/leftTicket/queryX?leftTicketDTO.train_date=2019-03-09&leftTicketDTO.from_station=HZH&leftTicketDTO.to_station=BJP&purpose_codes=ADULT)
 9 
10     return reque.json()[data][result]
11 
12 for i in pacong():
13     tem_list = i.split(|)
14 
15     if tem_list[32] != ‘‘ and tem_list[32] != :
16         print("", tem_list[3], "二等座\t", "出发时间:", tem_list[8], "到达时间:\t", tem_list[9], tem_list[32])
17     else:
18         print("")
19 """
20     #查看需要的信息所在的下標
21     print (tem_list)
22     p = 0
23     for n in tem_list:
24         print (p, n)
25         p += 1
26 """

 

5、結果:

技术图片

 

獲取12306所需剩餘的票

标签:三方   rom   url   res   date   result   imp   div   on()   

原文地址:https://www.cnblogs.com/hui-shao/p/python_12306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!