前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 ># python # # Challenge # Level 4

# python # # Challenge # Level 4

作者头像
滚神大人
发布2019-09-10 18:52:25
4150
发布2019-09-10 18:52:25
举报
文章被收录于专栏:趣Python趣Python

这个是 Python Challenge 的 Level 4。

点开页面是linkedlist.php,链到这个链接,是一幅图:

这个图有一点点提示,图片的名称是:chainsaw,链锯,点击图片,会跳转到一个页面: http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345 这个页面的内容是and the next nothing is 44827 再看第一个网页的源代码(老套路):

代码语言:javascript
复制
<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的积累,代码很容易:

代码语言:javascript
复制
# coding=utf-8 
# linkedlist

import urllibcount = 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的提示):

代码语言:javascript
复制
Yes. Divide by two and keep going.
peak.html
[Finished in 116.1s]

点评:

  • 这个题目不明所以
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-03-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 趣Python 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档