import timeimport jsonimport pprintimport mysqldbimport urllib2import Sudspagenum = range (1,1000) for a in pagenum: url = " Http://x.x.x.x:xx/agentProxy/getCallDetail? rn=118117&calltype=1&entid=xxxx&pwd=xxxx&starttime=20170516000000&endtime=20170516235959 &pagenum= " + str (a) req = urllib2. Request (URL) res_data = urllib2.urlopen (req) res = res_data.read () data = json.loads (res) data1 = data[0] data2 = data1["Calldetailarray"] data4 = data1["RetCode"] data5 = data1["RETMSG"] data6 = data1["Nextpagenum"] data7 = data1["RN"] data8 = data1["Entid"] if len (data1[' CallDetailArray ']) == 0: break #print "Return code:", DATA4 , "Whether successful:", Data5, "Next:", Data6, "RN:", Data7, "Enterprise number:", DATA8, "total number of pages on this page:", Len (data1[' Calldetailarray ')) data9 = len (data1[' Calldetailarray ') l = range (len (data1[') Calldetailarray '])) for i in l: data3 = (Data2[i]) data10 = int (data3[' sessionId ') data11 = hex (DATA10) data12 = data11[2:]  DATA13 = DATA12[:-1]        DATA14 = STR ( data3[' resourceId ') &Nbsp; data15 = time.strftime ("%y-%m-%d %x", Time.localtime ()) url = "http://x.x.x.x:xx/ DCMSWEBSERVICE/WEBSERVICE/QUERYRECORD?WSDL " client= Suds.client.Client (URL) res = client.service[' Queryrecord '].queryrecordaddr ("xxxxxxxxx", Data14,data14,data13) record= str (RES) print record db = mysqldb.connect ("x.x.x.x", "UCDs", "UCDs", "Report_detail", CharSet = "UTF8") cursor = db.cursor () sql = "" "insert into outbound (Record_url, Sessionid_16,sessionid,resourceid,resourcename,resourcedn,skilliD,remoteurl,localurl,starttime,endtime, alertduration, Talkduration,acwduration,ivrduration,joinduration,endtype,inserttime) values ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s") " "" % (record,data13,data3[' sessionId '), data3[' resourceId '],data3[' resourcename '],data3[' Resourcedn '], data3[' skillid '],data3[' Remoteurl '],data3["Localurl '],data3[' startTime '],data3[' EndTime '],data3[' alertduration '],data3[' talkduration '],data3["acwduration '],data3[' ivrduration '],data3[' Joinduration '],data3[' Endtype '],data15) cursor.execute (SQL) db.commit () Cursor.close () db.close () print "co-sync:", (A-1) *100-int (data9), "Bar data"
This article is from the "4574909" blog, please be sure to keep this source http://4574909.blog.51cto.com/4564909/1929229
Python invokes HTTP interface and incorporates MySQL database