問題鏈接
問題鏈接如下:
http://www.pythonchallenge.com/pc/def/ocr.html
答案鏈接
答案鏈接如下:
http://www.pythonchallenge.com/pc/def/equality.html
解題思路
根據(jù)頁面提示:
recognize the characters. maybe they are in the book,
but MAYBE they are in the page source.
閱讀源碼遗锣,有如下內(nèi)容:
<!--
find rare characters in the mess below:
-->
<!--
......
......
......
-->
編寫代碼從中提取出字符串即可:
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
即得到最終鏈接瞧哟。