pythonchallenge Level 17
第17关地址:http://www.pythonchallenge.com/pc/return/romance.html
账号:huge 密码:file
页面是cookie,猜测与cooike相关
左下角是第4关图片:http://www.pythonchallenge.com/pc/def/linkedlist.php
第4关是follow the chain,所以需要连续读取cookie的信息
查看cookie发现一个info信息:you should have followed busynothing...
使用第4关的地址,url改成busynothing
http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=12345
import re from urllib.request import urlopen from bs4 import BeautifulSoup infoText = [] def findurl(url): html = urlopen(url) text = html.info()["Set-Cookie"] reg = re.compile('info=(.*); exp') info = ''.join(reg.findall(text)) print(info) infoText.append(info) bsobj = BeautifulSoup(html, "html.parser") info = bsobj.text num = info.split(" ")[-1] if num.isdigit(): url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=" + str(num) print(url) findurl(url) else: print(info) url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=12345" findurl(url)
修改脚本,把获取到的info信息拼起来,解码
import bz2 import re from urllib import parse from urllib.request import urlopen from bs4 import BeautifulSoup def findurl(url): html = urlopen(url) text = html.info()["Set-Cookie"] print(text) reg = re.compile('info=(.*); exp') info = ''.join(reg.findall(text)) infoText.append(info) bsobj = BeautifulSoup(html, "html.parser") info = bsobj.text num = info.split(" ")[-1] if num.isdigit(): url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=" + str(num) print(url) findurl(url) else: print(info) url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=12345" infoText = [] findurl(url) newInfo = "".join(infoText) # newInfo = "BZh91AY%26SY%94%3A%E2I%00%00%21%19%80P%81%11%00%AFg%9E%A0%20%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.decompress(parse.unquote_to_bytes(newInfo.replace('+', '%20'))).decode('ascii'))
得到提示信息
is it the 26th already? call his father and inform him that "the flowers are on their way". he'll understand.
百度查莫扎特的父亲 Leopold Mozart
call his father,使用13关 pb.phone("Leopold")
得到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
显示了莫扎特父亲的画像
根据之前提示:inform him that "the flowers are on their way"
cookie的info带上the flowers are on their way
import requests url = "http://www.pythonchallenge.com/pc/stuff/violin.php" headers = { 'Cookie': 'info=the flowers are on their way' } response = requests.request("GET", url, headers=headers) print(response.text)
打印返回信息可以看到
<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>
得到提示:
it's me. what do you want?
oh well, don't you dare to forget the balloons.
获得下一关地址:http://www.pythonchallenge.com/pc/return/balloons.html