码迷,mamicode.com
首页 > 编程语言 > 详细

[解决方案] pythonchallenge level 4

时间:2015-05-07 00:27:45      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

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

查看页面源代码或者点击图片

http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

and the next nothing is 44827

本题将页面中的数字代替url中nothing的值

python:

import re
import requests
burl=‘http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=‘
new=u‘12345‘
res=re.compile(r‘and the next nothing is (\d+)‘)
while 1:
  gurl=requests.get(burl+str(new))
  content=gurl.text
  print content
  try:
    value=re.findall(res,gurl.text)[0]
    new,old=value,new
  except:
    status=raw_input(‘continue or break(c/b):‘)
    if status==‘c‘:
        rnew=raw_input(‘input the next nothing is number(default:%s/2)):‘ % new)
        if not rnew:
            new = int(new)/2
        else:
            new = int(rnew)
    else:
        break

最后得到:peak.html

 

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

[解决方案] pythonchallenge level 4

标签:

原文地址:http://www.cnblogs.com/hsp401/p/4483509.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!