<www.pythonchallenge.com>----Lv2

http://www.pythonchallenge.com/

一个有趣的python学习网站,就是在给出的图片和提示信息的帮助下,利用python解谜,然后进入下一关。

第二关:http://www.pythonchallenge.com/pc/def/ocr.html 

第二关的hint

recognize the characters. maybe they are in the book, 
but MAYBE they are in the page source.


很容易看出应该是在网页源码中找答案。

我看查看网页源码,会发现这样一句话

<!--
find rare characters in the mess below:
-->

<!--
%%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{*
@##&{#&{&)*%(]{{([*}@[@&]+!!*{)!}{%+{))])[!^})+)$]#{*+^((@^@}$[**$&^{$!@#$%)!@(&
+^!{%_$&@^!}$_${)$_#)!({@!)(^}!*^&!$%_&&}&_#&@{)]{+)%*{&*%*&@%$+]!*__(#!*){%&@++
!_)^$&&%#+)}!@!)&^}**#!_$([$!$}#*^}$+&#[{*{}{((#$]{[$[$$()_#}!@}^@_&%^*!){*^^_$^
]@}#%[%!^[^_})+@&}{@*!(@$%$^)}[_!}(*}#}#___}!](@_{{(*#%!%%+*)^+#%}$+_]#}%!**#!^_
)@)$%%^{_%!@(&{!}$_$[)*!^&{}*#{!)@})!*{^&[&$#@)*@#@_@^_#*!@_#})+[^&!@*}^){%%{&#@
@{%(&{+(#^{@{)%_$[+}]$]^{^#(*}%)@$@}(#{_&]#%#]{_*({(])$%[!}#@@&_)([*]}$}&${^}@(%
。。。。。。。。。。。。。。。很多。。。。。。。。。。。。。。。。。。

后面是更多的符号,意思就是要我们在这一堆符号你找出字符串,要手动找显然不可能,肯定用python,我想到用正则表达式re模块。

将那一堆符号保存在一个txt中,编写python代码:

import  re

str=open('/root/python/test1.txt', 'r').read()
p=re.compile("[a-z]+")
s=p.findall(str)
print ''.join(s)

输出结果:

>>> equality

这就是进入下一关的key,将网址改为equality.html进入下一关。

看了网址的答案后发现,方法一大堆,受益匪浅。

这一关目的是要我们掌握正则表达式。

看看这两篇文章

http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html

http://www.jb51.net/article/15707.htm

原文地址:https://www.cnblogs.com/luobuda/p/pythonchallenge-Lv2.html