2014年10月7日 星期二 晴 Level17 http://www.pythonchallenge.com/pc/return/romance.html
图片起初我以为是土豆,但细看是饼干。HTML源码Title是“eat?”,只有cookies.jpg,没有其他任何东西了。 图片不是那种让人处理的图片了,因为没有啥奇怪的特征。大图左下角的小图暗示是前面出现的一关linkelist。即http://www.pythonchallenge.com/pc/def/linkedlist.php
而cookies,让人想到的只有爬网站或者做网站存储东西的那个cookie了。
在Firefox中安装Firebug扩展是可以直接查看和编辑cookie的,很方便。 查看http://www.pythonchallenge.com/pc/def/linkedlist.php , cookie名称:info,cookie内容:you should have followed busynothing…
查看http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345 没有新内容
查看http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=12345 页面显示:If you came here from level 4 - go back!You should follow the obvious chain… and the next busynothing is 44827。 cookie名称:info,cookie内容:B
问弦歌而知道雅意,看来又要做一次遍历,把cookie内容都记录下来,最后组成通关密码或者线索。 代码: [code]def Challenge17(): import urllib2, cookielib auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(‘inflate’, ‘www.pythonchallenge.com’, ‘huge’, ‘file’) jar = cookielib.CookieJar() cookie_handler = urllib2.HTTPCookieProcessor(jar) opener = urllib2.build_opener(auth_handler, cookie_handler)
url = ‘http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=%s' answer_obj = re.compile(‘‘’next busynothing is (\d+)’’’) key = ‘12345’ info = [] for loop in xrange(400): rsp = opener.open(url % key).read() if rsp: objs = answer_obj.findall(rsp) if objs: key = objs[0] info.append(list(jar)[0].value) else: if ‘Divide by two’ in rsp: key = int(key) / 2 else: break
print url % (str(key)) rsp = get_url_data(url % (str(key))) if rsp: print rsp print ‘’.join(info) [/code] 打印出来 http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=83051 that’s it. BZh91AY%26SY%94%3A%E2I%00%00%21%19%80P%81%11%00%AFg%9E%A0+%00hE%3DM%B5%23%D0%D4%D1%E2%8D%06%A9%FA%26S%D4%D3%21%A1%EAi7h%9B%9A%2B%BF%60%22%C5WX%E1%ADL%80%E8V%3C%C6%A8%DBH%2632%18%A8x%01%08%21%8DS%0B%C8%AF%96KO%CA2%B0%F1%BD%1Du%A0%86%05%92s%B0%92%C4Bc%F1w%24S%85%09%09C%AE%24
没想到还没直接显示答案,字串看起来像之前做过的bz2编码,再解码一下。
直接decompress()一下,提示invalid data stream,只好网上搜了一下。 [code]def Challenge17b(): import urllib,bz2 info = ‘‘‘BZh91AY%26SY%94%3A%E2I%00%00%21%19%80P%81%11%00%AFg%9E%A0+%00hE%3DM%B5%23%D0%D4%D1%E2%8D%06%A9%FA%26S%D4%D3%21%A1%EAi7h%9B%9A%2B%BF%60%22%C5WX%E1%ADL%80%E8V%3C%C6%A8%DBH%2632%18%A8x%01%08%21%8DS%0B%C8%AF%96KO%CA2%B0%F1%BD%1Du%A0%86%05%92s%B0%92%C4Bc%F1w%24S%85%09%09C%AE%24%90’’’ print bz2.BZ2Decompressor().decompress(urllib.unquote_plus(info))[/code]
解码得出: is it the 26th already? call his father and inform him that “the flowers are on their way “. he’ll understand.
这道题又让我想起了莫扎特1月27日的生日,后面感觉像黑社会或者地下党的口吻。有call还有消息,这道题应该是前面n道题的综合题,算是复习了,XML-RPC。
搜索得知莫扎特父亲叫Leopold Mozart,给他打电话吧 [code]def Challenge17c(): import xmlrpclib uri = “http://www.pythonchallenge.com/pc/phonebook.php" pb = xmlrpclib.ServerProxy(uri) print pb.phone(“Leopold”) [/code] 得到555-VIOLIN,随即访问http://www.pythonchallenge.com/pc/return/violin.html ,得到提示no! i mean yes! but ../stuff/violin.php.,再访问http://www.pythonchallenge.com/pc/stuff/violin.php 显示leopold.jpg,表明是Leopold的照片。it’s me. what do you want? 呃,我想无机物要告诉他“the flowers are on their way”才行。
在Firebug里直接编辑cookie,info的内容为the flowers are on their way,则网页显示出“oh well, don’t you dare to forget the balloons .”。如果是要写python代码的话,是下面这样写的: [code]def Challenge17d(): import urllib2 url = ‘http://www.pythonchallenge.com/pc/stuff/violin.php' msg = ’the flowers are on their way’ req = urllib2.Request(url = url, headers={‘Cookie’: ‘info=’ + urllib.quote_plus(msg)}) rsp = urllib2.urlopen(req).read() print rsp[/code]
...