- A plenty of cookies. There is also a small picture on the lower left corner, remember it? It's the same photo as level 4. (I don't remember. Really.)
- Obviously, we should find out the cookies sent by level 4 webpage.
- See also: https://docs.python.org/2/library/cookielib.html
import cookielib, urllib2 cookies = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies)) webpage = opener.open("http://www.pythonchallenge.com/pc/def/linkedlist.php") for c in cookies: print c.name+" : "+c.value- The result showes:
info : you+should+have+followed+busynothing...- Seems we have to follow the procedure solving level 4 ...the new procedure will end at the 116th iteration.
link = "http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=" var = 12345 next_var = 0 cookie_list = [] for i in range(400): new_link = link + str(var) new_cookies = cookielib.CookieJar() new_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(new_cookies)) f = new_opener.open(new_link) cookie_list.append(new_cookies) urlcontent = f.read() try: next_var = re.findall("and the next busynothing is (\d+)", urlcontent) var = int(''.join(next_var)) f.close() except: break cookie_info = [] for i in cookie_list: for j in i: cookie_info.append(j.value) print ''.join(cookie_info)- The result is a string:
BZh91AY%26SY%94%3A%E2I%21%19%80P%81%11%AFg%9E%A0+hE%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- Remember that? A string starts with BZH91AY? See level 8!
- Remember to use urllib.unquoat_plus() to replace %xx escapes.
- The result shows: is it the 26th already? call his father and inform him that "the flowers are on their way". he'll understand.
- 26th? Recall Mozart in level 15! Call his father? Google him! Mozart's father is Leopold. Before we call Leopold, we have to know his phone number. Again, remember level 13?
- We could obtain "555-VIOLIN", and they want us to visit http://www.pythonchallenge.com/pc/stuff/violin.php. "It's me. What do you want?" Leopold said.
- Now we have to let him know "the flowers are on their way".
cookies = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies)) webpage = opener.open("http://www.pythonchallenge.com/pc/def/linkedlist.php") for c in cookies: c.value = "the flowers are on their way" new_webpage = opener.open("http://www.pythonchallenge.com/pc/stuff/violin.php") print new_webpage.read()- The returned webpage shows:
<html> <head> <title>it's me. what do you want?</title> <link rel="stylesheet" type="text/css" href="../style.css"> </head> <body> <br><br> <center><font color="gold"> <img src="leopold.jpg" border="0"/> <br><br> oh well, don't you dare to forget the balloons.</font> </body> </html>- Finnaly, the answer is "balloons". What a huge work!
沒有留言:
張貼留言