PythonChallenge-3-2017/7/14

接上一话,第三关入口:http://www.pythonchallenge.com/pc/def/ocr.html,页面如下:

红字的大概意思是,识别字符,它们可能在书中,也可能在页面源代码中,好吧,直接看源代码吧,在最后找到一大堆鬼东东,上面有提示在里面找字符:

话说这一堆东西里有字符?我是先复制到txt里Ctrl+F搜了一下‘a’,还真有,那就用程序找吧:

s = ''
with open('test.txt') as f:
    for i in f.readlines():
        for m in i:
            if ord('z')>=ord(m)>=ord('a'):
                s = s + m
print(s)

s 就是找到字符的集合

闲这堆东西太多,好吧,用爬虫爬下来吧:

url = 'http://www.pythonchallenge.com/pc/def/ocr.html'
import urllib.request
data = urllib.request.urlopen(url).read().decode()
#print(data)
import re
res = re.compile('<!--(.*?)-->',re.S).findall(data,re.S)
#print(res[1])
s = ''
for m in res[1]:
    if ord('z')>=ord(m)>=ord('a'):
        s = s + m
print(s)

不用保存本地了,直接在正则找到的结果里搜字符。

结果:equality

所以第四关入口:http://www.pythonchallenge.com/pc/def/equality.html

                                                  2017.7.14-----羽凡

posted @ 2017-07-14 18:35  羽化凡  阅读(91)  评论(0编辑  收藏  举报