# python # # Challenge # Level 4


这个是 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”号,谢谢 - ↓) 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值