美文网首页
Python Challenge 第6关

Python Challenge 第6关

作者: alabiubiubiu | 来源:发表于2016-07-09 07:46 被阅读37次

地址:http://www.pythonchallenge.com/pc/def/channel.html

代码

from urllib import request
import io
import re
import zipfile

file_name_next = "90052"
comment = ''

zip_get = request.urlopen("http://www.pythonchallenge.com/pc/def/channel.zip")
zip_file = io.BytesIO(zip_get.read())
channel_zip = zipfile.ZipFile(zip_file, "r")

while True:
    file_comment = channel_zip.getinfo(file_name_next+".txt").comment.decode("utf-8")
    comment += file_comment
    with channel_zip.open(file_name_next+".txt", "r") as f:
        file_content = f.read().decode('utf-8')
    try:
        file_name_next = re.search(r"\d+", file_content).group(0)
    except:
        break

print(comment)

zip_file.close()

运行结果

运行结果

学到的东西

import io

StringIO和BytesIO是在内存中操作str和bytes的方法,使得和读写文件具有一致的接口。

s = StringIO() 
s.write(‘hello’) 
s.write(’ ‘) 
s.write(‘world’) 
s.getvalue() 
‘hello world’

import zipfile

import re

from urllib import request

相关文章

  • Python Challenge 第6关

    地址:http://www.pythonchallenge.com/pc/def/channel.html 代码 ...

  • Python挑战:04-05关

    Python Challenge Python Challenge 04 现在,我们来挑战第四关,从第三关的结果,...

  • Python Challenge 第3关

    地址:http://www.pythonchallenge.com/pc/def/linkedlist.php

  • Python Challenge 第5关

    地址:http://www.pythonchallenge.com/pc/def/peak.html 需要使用到的...

  • Python Challenge 第3关

    第3关 没看懂题目,大概意思是一个小写字母,两边是三个大写字母。页面内没有内容,应该跟上一题一样在源码中。果然,源...

  • Python Challenge 第2关

    第2关 提示信息,在书或页面中找出字符。答案应该藏在页面源码中。 如下图所示,下载内容中提示在下方内容中找到稀有字...

  • Python Challenge 第0关

    Python Challenge 刷某乎的时候看到有推荐python编程跳转,感觉挺好玩的,就刷了一些,写篇帖子记...

  • Python Challenge 第1关

    第1关 根据图片可以看出每个字母往后推移了2步,得到后面的字母。后面给了一段话,嗯~~~ 意思很明显了,让我们根据...

  • [Python Challenge通关]第6关 now ther

    挑战地址,点我 分析 右键查看网页源代码看一下: 中间一长段的注释是在说捐赠的事情,并且作者说明了与这一关的问题没...

  • Python挑战:00~03关

    Python Challenge Python Challenge 00 网址: http://www.pytho...

网友评论

      本文标题:Python Challenge 第6关

      本文链接:https://www.haomeiwen.com/subject/zhmrjttx.html