PythonChallenge-4地址 :
http://www.pythonchallenge.com/pc/def/linkedlist.php
这里没什么提示,查看页面源代码,发现了一些信息
题目解析:这里得意思是通过页面源代码解析,要打开链接http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345,然后获取nothing值,一直循环直到得出答案,这里还给出提示要用urllib库
代码
from urllib import request,parse
import re
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?'
data ={}
data['nothing']="12345"
def GetNothing(url,data):
data = parse.urlencode(data)
url = url + data
re = request.Request(url)
page = request.urlopen(re).read().decode('utf-8') #获取请求页面,并utf-8解码
return page
for i in range(251):
HtmlPage = GetNothing(url,data) #获取页面
regex = re.compile('\d+')
NothingNum = re.findall(regex,HtmlPage) #匹配所有带数字得字符串
if NothingNum:
data['nothing'] = NothingNum[0] #取第一个NothingNum值
if len(NothingNum)>1:
data['nothing'] = NothingNum[1] #取第二个Nothing值
else:
data['nothing'] = str(int(data['nothing'])/2) #当前data['nothing']值减半
print(HtmlPage)
print(data['nothing'])
答案:250------peak.html
这里有几个比较坑得地方
85 ---- Yes. Divide by two and keep going
...
...
...
140 ---- There maybe misleading numbers in the
text. One example is 82683. Look only for the next nothing and the next nothing is 63579
因此才会出现条件判断,直接获取的话可能会出现Bug
PythonChallenge-5地址 :
http://www.pythonchallenge.com/pc/def/peak.html
题目解析:源代码中有个链接,下载一个banner.p的文件。
根据题目的意思就是要使用pickle.load(),将下载的文件进行反序列化,但是这里由于我文件下载不下来,将其内容保存下来好像文件格式不行,因此这里没做出来
这里关于pickle库得介绍可以参考下面链接:
https://www.cnblogs.com/baby-lily/p/10990026.html
下面是代码
import pickle
path = r"./other/banner.p"
f = open(path,'rb+')
bb = pickle.load(f)
f.close()
for li in bb:
for tu in li:
for i in range(int(tu[1])): #这个循环是将每个括号里面的第一个字符进行输出
print(tu[0], end='')
print("")
序列化之后得格式为
[[(' ', 95)], [(' ', 14), ('#', 5), (' ', 70), ('#', 5), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 6), ('#', 3), (' ', 6), ('#', 4), (' ', 3), ('#', 3), (' ', 9), ('#', 3), (' ', 7), ('#', 5), (' ', 3), ('#', 3), (' ', 4), ('#', 5), (' ', 3), ('#', 3), (' ', 10), ('#', 3), (' ', 7), ('#', 4), (' ', 1)], [(' ', 3), ('#', 3), (' ', 3), ('#', 2), (' ', 4), ('#', 4), (' ', 1), ('#', 7), (' ', 5), ('#', 2), (' ', 2), ('#', 3), (' ', 6), ('#', 4), (' ', 1), ('#', 7), (' ', 3), ('#', 4), (' ', 1), ('#', 7), (' ', 5), ('#', 3), (' ', 2), ('#', 3), (' ', 5), ('#', 4), (' ', 1)], [(' ', 2), ('#', 3), (' ', 5), ('#', 3), (' ', 2), ('#', 5), (' ', 4), ('#', 4), (' ', 3), ('#', 3), (' ', 3), ('#', 4), (' ', 4), ('#', 5), (' ', 4), ('#', 4), (' ', 2), ('#', 5), (' ', 4), ('#', 4), (' ', 3), ('#', 3), (' ', 5), ('#', 3), (' ', 3), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 3), (' ', 4), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 6), ('#', 4), (' ', 2), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 10), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 7), ('#', 3), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 5), ('#', 2), (' ', 3), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 7), ('#', 3), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 10), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 14), (' ', 2), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 4), ('#', 4), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 12), ('#', 4), (' ', 1)], [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 5), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 12), ('#', 4), (' ', 1)], [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 5), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 12), ('#', 4), (' ', 1)], [(' ', 2), ('#', 3), (' ', 6), ('#', 2), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 4), ('#', 4), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 3), (' ', 6), ('#', 2), (' ', 3), ('#', 4), (' ', 1)], [(' ', 3), ('#', 3), (' ', 4), ('#', 2), (' ', 3), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 11), (' ', 3), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 4), ('#', 3), (' ', 4), ('#', 2), (' ', 4), ('#', 4), (' ', 1)], [(' ', 6), ('#', 3), (' ', 5), ('#', 6), (' ', 4), ('#', 5), (' ', 4), ('#', 2), (' ', 4), ('#', 4), (' ', 1), ('#', 6), (' ', 4), ('#', 11), (' ', 4), ('#', 5), (' ', 6), ('#', 3), (' ', 6), ('#', 6)], [(' ', 95)]]
最终形成一幅图
很明显这是一个字符channel
PythonChallenge-6地址 :
题目解析:源码提示“zip”,随即尝试将网页地址中的“html”换成“zip”,提示下载压缩包
在压缩包中,读取readme.txt 后
welcome to my zipped list.
hint1: start from 90052
hint2: answer is inside the zip
和nothing一样,要一个一个读取压缩包里面的文件。
这里就用到了zipfile模块,下面是模块介绍:
https://www.jianshu.com/p/b9da5fd2e5cf
解题代码:
import zipfile
ZipFile = zipfile.ZipFile('file/channel.zip','r') #打开压缩包文件
nothing = '90052' #这里题目提示丛最后开始
li = []
def GetNothing(nothing):
i = 0
if i < len(ZipFile.namelist()):
filename = nothing + '.txt'
if filename in ZipFile.namelist(): #读取文件名
text = ZipFile.read(ZipFile.getinfo(filename)).decode() #读取文件内容
nothing = str.split(text,' ')[-1] #读取文件有些内容中空格后面的内容
i = i + 1
li.append(ZipFile.getinfo(filename).comment.decode())
GetNothing(nothing)
else:
print('The End!')
GetNothing(nothing)
print(''.join(li)) #将li数组的内容拼接起来
得到结果:
这里访问下:http://www.pythonchallenge.com/pc/def/hockey.html
看到内容为:it's in the air. look at the letters.
这里毫无头绪 看别人写的才知道答案为:oxygen ,这也太脑洞了吧