Ashamed, this topic is to refer to other people's blog made out, the main difficulty in
1. How to get a zip file
2.comments is a thing, the original author also in the blog "What the hell is the comments?"
From this problem, I find that
1. The information is not necessarily only on this page, you can modify the URL to obtain additional information.
2. For information that you cannot understand in the tip, such as "comments" in the subject, you can try searching in the Python doc (this is often the key to solving the problem), and Python doc can be found in your installation folder
The code is as follows:
1 #http://www.pythonchallenge.com/pc/def/channel.html2 #Author: [Email protected]3 ImportOS4 ImportSYS5 ImportZipFile6 ImportRe7 Importurllib.request8 ImportUrllib.response9 defDownloadFile (URL):TenResponse =urllib.request.urlopen (URL) OneZP = open ('Channel.zip','WB') A Zp.write (Response.read ()) - zp.close () - the defAnalysis (chzip,arcname): -ZP = ZipFile. ZipFile (Chzip,'R') -Zp.extractall (path=arcname) - zp.close () +Flist =Os.listdir (arcname) - forFinchflist: +Txfile = open (Arcname+f,'R') A forLineinchTxfile: at Print(line) - - defFlow (Chzip,beg): -ZP = ZipFile. ZipFile (Chzip,'R') -NameList =zp.namelist () -Nowfile =Beg inDirpath ='./channel/' -Pat = Re.compile ('\d{1,5}') toComments ="' + whileTrue: -fname = Nowfile +'. txt' theComments + = str (zp.getinfo (fname). comment,encoding='Utf-8') *Zp.extract (fname,path=Dirpath) $f = open (Dirpath + fname,'R')Panax NotoginsengContent =F.readline () -Matchs =pat.findall (content) the + ifLen (matchs)! =0: ANowfile =Matchs[0] the Else: + Break - returnComments $ if __name__=='__main__': $Nowurl = R'Http://www.pythonchallenge.com/pc/def/channel.zip' - DownloadFile (Nowurl) - #Analysis (' Channel.zip ', './channel/') the Print(Flow ('Channel.zip','90052'))
Python Challenge Level 6