python挑战之level4

</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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值