The Python Challenge(3)

问题链接

问题链接如下:

http://www.pythonchallenge.com/pc/def/ocr.html

答案链接

答案链接如下:

http://www.pythonchallenge.com/pc/def/equality.html

解题思路

根据页面提示:

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

阅读源码,有如下内容:




编写代码从中提取出字符串即可:

from urllib import request
from html.parser import HTMLParser

class HandleComment(HTMLParser):
    def handle_comment(self, data):
        for c in data:
            if c.isalnum() or c == ' ':
                print(c, end='')

        print()


url = 'http://www.pythonchallenge.com/pc/def/ocr.html'
response = request.urlopen(url)
content = response.read()
hc = HandleComment()
hc.feed(str(content, 'utf-8'))
hc.close()

最终获得字符串equality,替换掉问题URL中的ocr即得到最终链接。

你可能感兴趣的:(The Python Challenge(3))