这个是 Python Challenge 的 Level 4。
点开页面是linkedlist.php,链到这个链接,是一幅图:
这个图有一点点提示,图片的名称是:chainsaw
,链锯,点击图片,会跳转到一个页面:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345
这个页面的内容是and the next nothing is 44827
再看第一个网页的源代码(老套路):
<html>
<head>
<title>follow the chain</title>
</head>
<body>
<!-- urllib may help. DON'T TRY ALL NOTHINGS, since it will never
end. 400 times is more than enough. -->
<center>
<a href="linkedlist.php?nothing=12345"><img src="chainsaw.jpg" border="0"/></a><br><br><font color="gold">
</center>
...
综上所述:
-
使用urllib库
-
遍历
?nothing=12345
子页面 -
不超过400次
有了上一个Level的积累,代码很容易:
# coding=utf-8
# linkedlist
import urllib
count = 400
header = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
start = "12345"
while count:
count -= 1
content = urllib.urlopen(header + start).read()
start = content.split()[-1]
if not start.isdigit():
print(content)
if __name__ == "__main__":
pass
运行结果(反正找到规律是不停的“算”,代码没去管Divide
的提示):
Yes. Divide by two and keep going.
peak.html
[Finished in 116.1s]
点评:
-
这个题目不明所以
(↓ - 有些内容只在小龙家发,可关注同名“趣Python”号,谢谢 - ↓)