第四题的画面上没有任何提示,直接查看源代码,有一句:
urllib may help. DON'T TRY ALL NOTHINGS, since it will never
end. 400 times is more than enough.
DON'T TRY ALL NOTHINGS是什么意思?
点击画面上的图片,跳转到http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345,画面上显示:and the next nothing is 92512
这下明白了,要修改URL中nothing后面的数字。改吧!当改到第三次的时候,画面上提示:Your hands are getting tired and the next nothing is 50010。 呵呵,有意思,印证了这句话:it will never end. 400 times is more than enough. 老老实实写程序吧。 最后的结果是peak.html
import urllib
import re
if __name__ == '__main__':
f = open('4.txt', 'w')
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
nothing = '12345'
#'46059' is from the result of execution of '12345'
#nothing = '46059'
# solution 1 Start
for i in range(500):
response = urllib.urlopen(url + nothing)
page = response.read()
f.write(str(i) + ': ' +page + '\n')
list = re.findall('the next nothing is \d*', page)
if len(list) > 0:
nothing = ''.join(d for d in list[0] if d.isdigit())
else:
break
#solution 1 End
#solution 2 Start:
print('solution 2: ')
findNothing = re.compile('the next nothing is (\d)*').search
while True:
text = urllib.urlopen(url + nothing).read()
print(text)
match = findNothing(text)
if match:
nothing = match.group(1)
else:
break
#solution 2 End:
f.close()
学习到了urllib的简单使用,javascript的group的用法。
分享到:
相关推荐
python challenge 全部解答
Python challenge 3的一种解法
http://www.pythonchallenge.com/上的题目,共33关,Python初学者可以根据上述题目进行练习,对提高Python编程水平很有帮助。
pythonchallenge level2官方方法集
如果您还没有听说过“Python挑战”,那么现在就试一试吧!我可以等待。 在你翻到下一页之前,要注意这本电子书包含了很多题目 所有的挑战,可能会破坏你的旅程。如果你不关心 如果你不打算吹嘘自己的“成就”,那就...
python challenge习题答案,蛮有意思的
www.pythonchallenge.com题解第五题,包含详细注释
www.pythonchallenge.com题解第四题,包含详细注释
www.pythonchallenge.com题解第二题,包含详细注释
www.pythonchallenge.com题解第一题,包含详细注释
www.pythonchallenge.com题解第三题,包含详细注释。
NULL 博文链接:https://kukuqiu.iteye.com/blog/441106
**有趣的Python Challenge编程游戏闯关攻略一(0-4关)**介绍关卡第0关第1关第2关第3关第4关链接总结 ...游戏链接:http://www.pythonchallenge.com/ 界面是这样的: Solutions to previous leve
Python挑战 我对 pythonchallenge.com 的解决方案
**有趣的Python Challenge编程解谜游戏第11关**介绍游戏介绍0-4关攻略5-9关攻略10关攻略第11关结果链接 ...游戏链接:http://www.pythonchallenge.com/ 界面是这样的: 看起来是没有啥有用的东西。。。还
python-challenge-源码.rar
python-challenge
Python-Challenge(1)-源码.rar
DT Challenge Python Chatbot
[Cash-Money](工作目录/作业/ Python / python-challenge / PyBank / cash-money.png) 在这个挑战中,您的任务是创建一个Python脚本来分析公司的财务记录。 计算以下各项: 数据集中包含的总月数 整个期间的...