Python Challenge (level 17)

URI: [url]http://www.pythonchallenge.com/pc/return/romance.html[/url]
Username: huge; password: file

说明:

解题方法:
import re, urllib, urllib2, bz2, xmlrpclib

# First of all, get the data that is hidden within the "Set-Cookie" headers:

uri = "http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=%s"
nn_rep = re.compile("the next busynothing is (\d+)")
cookie_val = re.compile("info=([^;]+);")
result = []
n = "12345"

while True:
h = urllib.urlopen(uri % n)
next = h.read()
cookie = h.info().getheader("Set-Cookie")
h.close()

cval = cookie_val.search(cookie)

if cookie and cval:
result.append(urllib.unquote_plus(cval.group(1)))

try:
n = nn_rep.search(next).group(1)
except:
break

print bz2.decompress("".join(result)

# Get Leopold's phone numer using the code for level 13:

conn = xmlrpclib.ServerProxy("http://www.pythonchallenge.com/pc/phonebook.php")

print conn.phone("Leopold")

# Now phone Mozart's father and tell him that "the flowers are on their way":

uri = "http://www.pythonchallenge.com/pc/stuff/violin.php"
msg = "the flowers are on their way"
req = urllib2.Request(
uri, headers = { "Cookie": "info=" + urllib.quote_plus(msg)}
)

print urllib2.urlopen(req).read()


过关答案:
balloons
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值