python挑战之level 17

来源:互联网 发布:淘宝网自动充值 编辑:程序博客网 时间:2024/05/22 15:25

连接:http://www.pythonchallenge.com/pc/return/romance.html

————————————————————————————————————————————

图片是一个饼干和一副小图,标题是:eat?   就没有其他的提示了

——————————————————————————————

百度了一下看看别人的思路:

1.The picture shows cookies, and there’s an inset with the sawhorse picture from level4 .

2.【首先通过cookies的提示,需要查看cookies信息,然后知道需要回到第四关,然后用busynothing 替代 nothing,重复第四关的遍历,不过这次需要收集的是每一个页面的cookies信息,然后利用bz2处理这些信息,然后再回到第13关打电话给mozart的老爹…用获得的信息修改新页面的cookies,最后得到谜底,

————————————————————————————————————————————————

这实在是超出我的能力,,继续:

开始我百度的信息实在过于太少,后来找到了一个视频。推荐给大家:

http://i.youku.com/i/UNjIxNDA5NTY=

————————————————————————————————————————————————————

# -*- coding: utf-8 -*-import  urllib.request,urllib.parseimport  http.cookiejarimport  re,bz2info=[]#建立cookie管理,和授权代理程序cookies=http.cookiejar.CookieJar()auth_handler = urllib.request.HTTPBasicAuthHandler()#添加密码到授权管理auth_handler.add_password('inflate', 'www.pythonchallenge.com', 'huge', 'file')#绑定cookiescookie_handler=urllib.request.HTTPCookieProcessor(cookies)#建立openerdirector对象opener=urllib.request.build_opener(cookie_handler,auth_handler)#打开链接reqs=opener.open('http://www.pythonchallenge.com/pc/def/linkedlist.php')reqs_data=reqs.info()print(reqs_data)print(list(cookies))

</pre>————————————————————————————————————————<p></p><p>这个读得的信息为:</p><p></p><pre code_snippet_id="1898672" snippet_file_name="blog_20160924_3_3470694" name="code" class="python">Set-Cookie: info=you+should+have+followed+busynothing...; expires=Sat, 01-Oct-2016 04:14:35 GMT; Max-Age=604800; path=/; domain=.pythonchallenge.comContent-type: text/html; charset=UTF-8Connection: closeTransfer-Encoding: chunkedDate: Sat, 24 Sep 2016 04:14:35 GMTServer: lighttpd/1.4.35[Cookie(version=0, name='info', value='you+should+have+followed+busynothing...', port=None, port_specified=False, domain='.pythonchallenge.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=False, expires=1475295274, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False)]
————————————————————————————————————————————————————————————————————————————
根据其中的信息:
you+should+have+followed+busynothing...
所以知道家该学第一关一样进行迭代。。

#定义下一页迭代函数def next_page():#使用列表保存每个网页的cookie中的value值    cookieinfo=b''    path='http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing='    busynothong='12345'    for i in range(400):            f=opener.open(path+busynothong).read()            text=f.decode('utf-8')            m = re.search('and the next busynothing is ([0-9]+)', text)            #如果匹配,取数字串,否则中断            if m:                busynothong = m.group(1)            else:                print('异常!')                break            print(text,busynothong)            #取出cookievs的value的值            cookieinfo+=(list(cookies)[0].value).encode('utf-8')    return cookieinfo
——————————————————————————————————————————————————————————————————————————————

然后把得到列表进行解码解压缩,但是我的电脑不知道怎么回事。。使用unquote()方法解码出来的是乱码,一直解决不了

所以引用的是别人的代码,我反正没试出来

cookie_bzd=bz2.decompress(urllib.unquote_plus(cookieinfo))  

——————————————————————————————————————————————————————

结果为:

is it the 26th already? call his father and inform him that "the flowers are on their way".he’ll understand.
——————————————————————————————————————————————————————————————————

这是利用第13关莫扎特的那个phone()方法,

import xmlrpc.clientserver = xmlrpc.client.Server(r'http://www.pythonchallenge.com/pc/phonebook.php')print (server.system.listMethods() )print (server.system.methodHelp('phone')  )print (server.phone('Leopold') )

————————————————————————————————————————————————————————————————

结果为:

'555-VIOLIN'
我们把13关的网址改为:http://www.pythonchallenge.com/pc/return/violin.html

得到的提示为:no! i mean yes! but ../stuff/violin.php.

然后我尝试一下新网页:http://www.pythonchallenge.com/pc/stuff/violin.php

标题为:it's me. what do you want?

那这是什么意思啊??

————————————————————————————————————————————————————

看看别人的答案。原来是要根据上面的答案:【

is it the 26th already? call his father and inform him that "the flowers are on their way".he’ll understand.
将其中
the flowers are on their way
存到cookie中

————————————————————————————————————————————————————————————————————

import urllib.request,urllib.parseurl='http://www.pythonchallenge.com/pc/stuff/violin.php'req = urllib.request.Request(url,headers={'Cookie':'info=the flowers are on their way'})rs=urllib.request.urlopen(req)print(rs.read())
————————————————————————————————————————————————————————————

最终得到的答案为:

noh well, don\'t you dare to forget the balloons.

所以下一关的连接:http://www.pythonchallenge.com/pc/return/balloons.html


0 0
原创粉丝点击