慢慢开始熟悉python challenge的题风了. 精华就是基本得靠猜,呵呵
第三题: http://www.pythonchallenge.com/pc/def/ocr.html
题目是一张图片, 很模糊的写了一些字.提示是:
recognize the characters. maybe they are in the book, but MAYBE they are in the page source.
第一反应是需要对图片做文字提取.可这图片的分辨率着实太低,恐怕任何算法都难以提取出需要的内容. 第二反应恐怕又是被提示幽了一默. 很明显but后面才是重点. 于是打开view source. 得到真正关键的提示:
<!-- | |
find rare characters in the mess below: | |
--> | |
接下来是一堆乱码,夹杂了若干字母,基本可以确定答案就是这几个字母.
首先把这堆乱码存成了一个txt文件,名字为view-source, 然后就是从文件中读出来当作一个字符串处理. 使用isalpha()分析是否为字母, 最后返回一个字符串即可.
#read the file as string, check whether has letters
def searchCharator(fileInput):
resultStr = ''
inputStr=fileInput.read()
for char in inputStr:
if char.isalpha():
resultStr += char
return resultStr
#store the page source as txt file
frd = open('view-source.txt','r')
print(searchCharator(frd))
可以得知下一关的地址为:
http://www.pythonchallenge.com/pc/def/equality.html