2424import codecs
2525import argparse
2626import os
27+ import time
2728
2829class hackTickets (object ):
2930 """docstring for hackTickets"""
3031
3132 """读取配置文件"""
3233 def readConfig (self , config_file = 'config.ini' ):
34+ print ("加载配置文件..." )
3335 # 补充文件路径,获得config.ini的绝对路径,默认为主程序当前目录
3436 path = os .path .join (os .getcwd (), config_file )
3537
@@ -90,8 +92,10 @@ def loadConfig(self):
9092 加载映射文件,并将中文"武汉"转换成编码后的格式:“武汉,WHN“
9193 """
9294 def loadCityCode (self ):
95+ print ("映射出发地、目的地..." )
9396 city_codes = {}
94- with open ('city_code.txt' , 'r+' ) as f :
97+ path = os .path .join (os .getcwd (), 'city_code.txt' )
98+ with codecs .open (path , "r" , "utf-8-sig" ) as f :
9599 for l in f .readlines ():
96100 city = l .split (':' )[0 ]
97101 code = l .split (':' )[1 ].strip ()
@@ -113,6 +117,7 @@ def __init__(self):
113117 self .loadConfig ();
114118
115119 def login (self ):
120+ print ("开始登录..." )
116121 # 登录
117122 self .driver .visit (self .login_url )
118123 # 自动填充用户名
@@ -162,6 +167,7 @@ def preStart(self):
162167 self .driver .cookies .add ({"_jc_save_fromDate" : self .dtime })
163168
164169 def buyTickets (self ):
170+ t = time .clock ()
165171 try :
166172 print (u"购票页面开始..." )
167173
@@ -231,6 +237,8 @@ def buyTickets(self):
231237 print (u"确认选座..." )
232238 self .driver .find_by_id ('qr_submit_id' ).click ()
233239
240+ print (time .clock () - t )
241+
234242 except Exception as e :
235243 print (e )
236244
@@ -251,5 +259,8 @@ def start(self):
251259 self .buyTickets ();
252260
253261if __name__ == '__main__' :
262+ print ("===========hack12306 begin===========" )
263+ begin = time .clock ()
254264 hackTickets = hackTickets ()
255265 hackTickets .start ()
266+ print (time .clock () - begin )
0 commit comments