Compared to the code that returns results, there is a problem, because there are multiple rows of data, only 1 lines can be written to Excel:
#-*-coding:utf-8-*-import httplib2,xlrd,xlwt,time,jsonfrom xlutils.copy import copydef time (): Tim=time.strftime ('%Y -%m-%d%h:%m:%s ', Time.localtime (Time.time ())) return Timprint "test begin:" +time () #开始时间oldwb =xlrd.open_workbook (R ' Url.xls ') oldsh = Oldwb.sheet_by_index (0) nrows=oldsh.nrowsnewwb=copy (OLDWB) newsh=newwb.get_sheet (0) #第一次调用xlrd, Xlwtdef gethttpstatus (URL): try:conn= httplib2. Http (disable_ssl_certificate_validation=true) start=time.time () req=conn.request (URL) end=time.time () diff= End-start return Req[0],diff except Exception as Err:return (Err,diff) #https请求方法, request time for I In range (1,nrows): Url1=oldsh.cell_value (i,1) url=url1 status=gethttpstatus (URL) [0][' status '] Reqtime=gethttps Tatus (URL) [1] newsh.write (i,2,status) Newsh.write (I,5,time ()) Newsh.write (i,6,reqtime) if Reqtime < 1.0: Newsh.write (i,7, ' Normal ') else:newsh.write (i,7, ' Timeout ') Ac_reusult=oldsh.cell (i,2). VAlue Ex_reusult=oldsh.cell (i,3). value if Ac_reusult = = EX_reusult:newsh.write (i,4, "PASS") Else:ne Wsh.write (i,4, "FAIL") newwb.save (' Url.xls ') #将复制过的数据保存在newurl. Xlsprint "Test over:" +time () #结束时间
Python Automation Comparison returns results