The Python Challenge(7)

问题链接

问题链接如下:

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

答案链接

答案链接如下:

http://www.pythonchallenge.com/pc/def/oxygen.html

解题思路

根据拉链,得到第一个关键字zip,再继续看源码,有如下信息:

<!-- <-- zip -->

试试将URL改为:http://www.pythonchallenge.com/pc/def/channel.zip,下载解压后,查看其中的readme.txt,有如下信息:

welcome to my zipped list.

hint1: start from 90052
hint2: answer is inside the zip

就是说,答案在zip本身,则有如下代码:

from os import path
from urllib import request
from zipfile import ZipFile
import re

channel_zip = path.join('/tmp', "channel.zip")

url = 'http://www.pythonchallenge.com/pc/def/channel.zip'
response = request.urlopen(url)
content = response.read()
with open(channel_zip, 'wb') as channel:
    channel.write(content)

channel = ZipFile(channel_zip, 'r')
hint = 'readme.txt'

while True:
    txt = str(channel.read(hint), 'utf-8')
    
    # Step 1
    print(txt)

    ret = re.findall('\W(\d+)(?:\s|$)', txt)
    if len(ret) == 0:
        break
    hint = ret[0]+'.txt'

最终有如下信息:

Collect the comments.

接下来修改代码,阅读zip的附件信息,则有如下代码:

from os import path
from urllib import request
from zipfile import ZipFile
import re

channel_zip = path.join('/tmp', "channel.zip")

url = 'http://www.pythonchallenge.com/pc/def/channel.zip'
response = request.urlopen(url)
content = response.read()
with open(channel_zip, 'wb') as channel:
    channel.write(content)

channel = ZipFile(channel_zip, 'r')
hint = 'readme.txt'
comment = ''

while True:
    txt = str(channel.read(hint), 'utf-8')
    
    # Step 1
    # print(txt)
    
    # Step 2
    print(str(channel.getinfo(hint).comment, 'utf-8'), end='')

    ret = re.findall('\W(\d+)(?:\s|$)', txt)
    if len(ret) == 0:
        break
    hint = ret[0]+'.txt'

输出信息如下所示:

****************************************************************
****************************************************************
**                                                            **
**   OO    OO    XX      YYYY    GG    GG  EEEEEE NN      NN  **
**   OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE  NN    NN   **
**   OO    OO XXX  XXX YYY   YY  GG GG     EE       NN  NN    **
**   OOOOOOOO XX    XX YY        GGG       EEEEE     NNNN     **
**   OOOOOOOO XX    XX YY        GGG       EEEEE      NN      **
**   OO    OO XXX  XXX YYY   YY  GG GG     EE         NN      **
**   OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE     NN      **
**   OO    OO    XX      YYYY    GG    GG  EEEEEE     NN      **
**                                                            **
****************************************************************
 **************************************************************

对应于字符串hockey,将URL改为: http://www.pythonchallenge.com/pc/def/hockey.html,输入到浏览器中,最终页面显示:

it's in the air. look at the letters.

再次观察组成hockey的字符,则得到字符串oxygen,则最终URL为: http://www.pythonchallenge.com/pc/def/oxygen.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容