python challenge 4 博客分类: python PythonPHPJavaScriptF#HTML
程序员文章站
2024-02-03 14:12:28
...
第四题的画面上没有任何提示,直接查看源代码,有一句:
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
学习到了urllib的简单使用,javascript的group的用法。
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 7 博客分类: python Python算法F#
-
python challenge 6 博客分类: python PythonOOAIR网页游戏游戏
-
python challenge 4 博客分类: python PythonPHPJavaScriptF#HTML
-
python语法学习整理 博客分类: Python
-
Python使用bs4获取58同城城市分类的方法
-
Python使用bs4获取58同城城市分类的方法
-
Python使用bs4获取58同城城市分类的方法
-
python采用requests+bs4爬取Gary个人博客学习页面并用mysql存储
-
Python使用bs4获取58同城城市分类的方法
-
python采用requests+bs4爬取Gary个人博客学习页面并用mysql存储