Pythonchallenge Level 17 (python 2.7)

本文详细记录了解决Python挑战中从Level42开始,通过使用Python代码逐步深入,最终到达Balloon页面的过程。利用Cookie、URL跳转、正则表达式等技术手段,实现信息抓取与解析,最终获取正确答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I spent much more time on this problem.
the information behind this pic:
1. the image from level4
2. lots of cookies
==> go into the corresponding cookies of level4 and you will find a hint:
'you+should+have+followed+busynothing...'
then repeat level 4 processes with the url (........./busynothing=....)
find the correct value
at the same time, during the loop, all pages including a cookie, try to figure out useful info.

Anyway, the code:
>>> import urllib2,cookielib,re
>>> cookies=cookielib.CookieJar()
>>> opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies))
>>> response=opener.open('http://www.pythonchallenge.com/pc/def/linkedlist.php')
>>> cookies


>>> value=12345
>>> match='(is) (\b+)'
>>> info=''
>>> while True:
str='http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=%s'%value
html=urllib2.urlopen(urllib2.Request(str))
request=opener.open(str)
for item in cookies:
if item.name=='info':
info=info+item.value
cont=html.read()
res=re.findall(match,cont)
if res[0][1]==value:
break
else:
value=res[0][1]
>>> import urllib
>>> ninfo=urllib.unquote_plus(info)
>>> ninfo
'BZh91AY&SY\x94:\xe2I\x00\x00!\x19\x80P\x81\x11\x00\xafg\x9e\xa0 \x00hE=M\xb5#\xd0\xd4\xd1\xe2\x8d\x06\xa9\xfa&S\xd4\xd3!\xa1\xeai7h\x9b\x9a+\xbf`"\xc5WX\xe1\xadL\x80\xe8V<\xc6\xa8\xdbH&32\x18\xa8x\x01\x08!\x8dS\x0b\xc8\xaf\x96KO\xca2\xb0\xf1\xbd\x1du\xa0\x86\x05\x92s\xb0\x92\xc4Bc\xf1w$S\x85\t\tC\xae$\x90'
>>> binfo=bz2.decompress(ninfo)
>>> binfo

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

>>> import xmlrpclib
>>> s=xmlrpclib.ServerProxy('http://www.pythonchallenge.com/pc/phonebook.php')
>>> s.phone('Leopold') # Leopold is his father

'555-VIOLIN'
#then go the 'http://www.pythonchallenge.com/pc/stuff/violin.php' whose title is 'it is me, what do you what?'
>>> req=urllib2.Request('http://www.pythonchallenge.com/pc/stuff/violin.php')
>>> req.add_header('Cookie','info=the flowers are on their way')
>>> response=opener.open(req)
>>> response.read()

the answer comes out. it is 'balloons.html'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值