pythonchallenge Level 4

第4关地址:http://www.pythonchallenge.com/pc/def/linkedlist.html

打开显示

 改成php打开

查看源码获得提示信息

标题:follow the chain

提示: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

 打开链接提示下一个数字

 替换数字几次后出现信息

也不能真的手动改400次,使用urllib打开,自动获取。

运行时发现没有停止,发现中间有一个going,改为只有数字的时候继续运行,如果不是数字,打印出页面信息。

from urllib.request import urlopen
from bs4 import BeautifulSoup

def findurl(url):
    html = urlopen(url)
    bsobj = BeautifulSoup(html, "html.parser")
    info = bsobj.text
    num = info.split(" ")[-1]
    if num.isdigit():
        url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + str(num)
        print(url)
        findurl(url)
    else:
        print(info)

url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345"
findurl(url)

 运行到16044时,获得提示信息:Yes. Divide by two and keep going.

16044/2 = 8022 修改url,重新运行

new_url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=8022"
findurl(new_url)

得到 peak.html

获得下一关地址:http://www.pythonchallenge.com/pc/def/peak.html

posted @ 2021-12-07 09:53  OTAKU_nicole  阅读(33)  评论(0编辑  收藏  举报