美文网首页
The Python Challenge(5)

The Python Challenge(5)

作者: 发条蛙 | 来源:发表于2017-10-20 17:26 被阅读0次

问题链接

问题链接如下:

http://www.pythonchallenge.com/pc/def/linkedlist.php

答案链接

答案链接如下:

http://www.pythonchallenge.com/pc/def/peak.html

解题思路

根据页面源码提示:

<!-- urllib may help. DON'T TRY ALL NOTHINGS, since it will never 
end. 400 times is more than enough. -->

再点击页面图片显示:

and the next nothing is 44827

可知是需要一直跳转,则有如下代码:

from urllib import request
import re

url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
id = '12345'
while True:
    response = request.urlopen(url+id)
    content = str(response.read(), 'utf-8')
    print(content)
    ret = re.findall('and the next nothing is (\d+)', content)
    if len(ret) == 0:
        print(url+id)
        break
    id = ret[0]

显示到如下内容,然后停止:

and the next nothing is 16044
Yes. Divide by two and keep going.

则把代码中的初始ID替换为8022,再次执行有如下结果:

and the next nothing is 66831
peak.html

则最终URL应当为:http://www.pythonchallenge.com/pc/def/peak.html

相关文章

  • Python挑战:00~03关

    Python Challenge Python Challenge 00 网址: http://www.pytho...

  • The Python Challenge(5)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面源码提示: 再点击页面图片显示: 可知是需要...

  • Python Challenge[5]

    [Level 5] Title: peak hell pronounce it 想不出,查看源码,找到banner...

  • Python挑战:04-05关

    Python Challenge Python Challenge 04 现在,我们来挑战第四关,从第三关的结果,...

  • Python challenge 第五关之——pickle序列化

    上周五下午同事发我一个Python challenge level 5的链接:http://www.pythonc...

  • Python Challenge 第5关

    地址:http://www.pythonchallenge.com/pc/def/peak.html 需要使用到的...

  • The Python Challenge(8)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 页面和源码中无任何提示,但图片中有一条很明显的灰度线...

  • The Python Challenge(9)

    问题链接 问题链接如下: 答案链接 答案链接如下: 登陆用户名密码为huge和file。 解题思路 阅读源码有如下...

  • The Python Challenge(2)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 将页面给定的字符串根据给定规则进行替换即可,规则如下...

  • The Python Challenge(3)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面提示: 阅读源码,有如下内容: 编写代码从中...

网友评论

      本文标题:The Python Challenge(5)

      本文链接:https://www.haomeiwen.com/subject/oxvvuxtx.html