</pre>链接:<a target=_blank href="http://www.pythonchallenge.com/pc/def/linkedlist.php">http://www.pythonchallenge.com/pc/def/linkedlist.php</a><p></p><p>查看网页源码:有提示:</p><p></p><pre code_snippet_id="1865947" snippet_file_name="blog_20160904_2_4813472" name="code" class="html"><!-- urllib may help. DON'T TRY ALL NOTHINGS, since it will never
end. 400 times is more than enough. -->
这是什么意思?
百度一下:
点击画面上的图片,跳转到http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345,
画面上显示:and the next nothing is 92512
这下明白了,要修改URL中nothing后面的数字。
改吧!当改到第三次的时候,画面上提示:Your hands are getting tired and the next nothing is 50010。
呵呵,有意思,印证了这句话:it will never end. 400 times is more than enough. 老老实实写程序吧。 最后的结果是peak.html
_________________________________________________________________________________________________________________
代码如下:
import re
from urllib import request
import sys
#with open('f.txt','r') as f:
# a=f.read()
nothing=sys.argv[1]
url_r="http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
url_all=url_r+nothing
for i in range(1,500):
try:
with request.urlopen(url_all) as f:
html=f.read()
#获得代码为bytes,转换为字符串
ht=(html).decode('utf-8')
print(ht)
#ht是列表对象,因此获取其中元素
nothing=re.findall(r'\d+',ht)[0]
#再组成新的url
url_all=url_r+nothing
except:
print(html,'异常')
break
输入第一个nothing=12345
运行:
python test.py 12345
</pre>中间会出现一个提示:<p><pre name="code" class="java">and the next nothing is 16044
Yes. Divide by two and keep going.
b'Yes. Divide by two and keep going.' 异常
根据提示:把数字除以2:
There maybe misleading numbers in the
text. One example is 82683. Look only for the next nothing and the next nothing is 63579
You've been misleaded to here. Go to previous
one and check.
再重新运行:
peak.html
b'peak.html' 异常
所以最终就是:
http://www.pythonchallenge.com/pc/def/peak.html