阅读616 返回首页    go 阿里云 go 技术社区[云栖]


pythonchallenge_level4

level4

地址:https://www.pythonchallenge.com/pc/def/linkedlist.php
源码:git@code.aliyun.com:qianlizhixing12/PythonChallenge.git。
问题:在页面源码中找出数字替换URL。

#!/usr/bin/env python3
# -*- coding:UTF-8 -*-

# Level 4

import urllib.request
import re

def fun(sid):
    url = "https://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + sid
    response = urllib.request.urlopen(url)
    body = response.read()
    response.close

    body = body.decode("utf8")
    nid = body.split(" ")[-1]

    if nid.isdigit():
            return fun(nid)
    elif body == "Yes. Divide by two and keep going.":
        sid = str(int(sid) / 2)
        return fun(sid)
    else:
        return body

if __name__ == "__main__":
    print("Level 4:", fun("12345"))

最后更新:2017-10-01 07:33:20

  上一篇:go  使用CentOS7 kvm虚拟机安装蓝鲸社区版(3.15)
  下一篇:go  pythonchallenge_level3