python爬取
python爬取火车票一点查询就中断 并且数据出不来这是我query_request.py的代码
from get_stations import *
import json
data=[]
type_data=[]
def query(date, from_station, to_station):
data.clear()
type_data.clear()
url='https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2019-10-13&leftTicketDTO.from_station=WHN&leftTicketDTO.to_station=HGH&purpose_codes=ADULT'.format(date, from_station,to_station)
response=requests.get(url)
result=response.json()
result=result['data']['result']
if isStations()==True:
stations=eval(read())
if len(result)!=0:
for i in result:
tem_list=i.split('|')
from_station=list(stations.keys())[list(stations.values()).index(tem_list[6])]
to_station=list(stations.keys())[list(stations.values()).index(tem_list[7])]
seat=3], from_station, to_station, tem_list[8], tem_list[9], tem_list[10], tem_list[32], tem_list[31], tem_list[30], tem_list[21], tem_list[23], tem_list[33], tem_list[28], tem_list[24], tem_list[29], tem_list[26]]
newSeat=[]
for s in seat:
if s=="":
s="--"
else:
s=s
newSeat.applend(s)
data.append(newSeat)
return (data)
def g_veniche():
if len(data)!=0:
for g in data:
i=g[0].startswith('G')
if i:
type_data.append(g)
def r_g_venivhe():
if len(data)!=0 and len(type_data)!=0:
for g in data:
i=g[0].startswith('G')
if i:
type_data.remove(g)
def d_venicle():
if(data)!=0:
for d in data:
i = d[0].startswith('D')
if i==True:
type_data.append(d)
def r_d_venivhe():
if len(data)!=0 and len(type_data)!=0:
for d in data:
i=d[0].startswith('D')
if i==True:
type_data.remove(d)
def z_venicle():
if(data)!=0:
for z in data:
i = z[0].startswith('Z')
if i==True:
type_data.append(z)
def r_z_venivhe():
if len(data)!=0 and len(type_data)!=0:
for z in data:
i=z[0].startswith('Z')
if i==True:
type_data.remove(z)
def t_venicle():
if(data)!=0:
for t in data:
i = t[0].startswith('T')
if i==True:
type_data.append(t)
def r_t_venivhe():
if len(data)!=0 and len(type_data)!=0:
for t in data:
i=t[0].startswith('T')
if i==True:
type_data.remove(t)
def k_venicle():
if(data)!=0:
for k in data:
i = k[0].startswith('K')
if i==True:
type_data.append(k)
def r_k_venivhe():
if len(data)!=0 and len(type_data)!=0:
for k in data:
i=k[0].startswith('K')
if i==True:
type_data.remove(k)
我debug 一直出现这个 然后网上查说是json文件数据转不过来
页:
[1]