問題鏈接
問題鏈接如下:
http://www.pythonchallenge.com/pc/def/equality.html
答案鏈接
答案鏈接如下:
http://www.pythonchallenge.com/pc/def/linkedlist.php
解題思路
根據(jù)頁面提示:
One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.
并結(jié)合頁面源碼中的內(nèi)容题禀,有如下代碼:
from urllib import request
from html.parser import HTMLParser
import re
class HandleComment(HTMLParser):
def handle_comment(self, data):
ret = re.findall('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', data)
print(''.join(ret))
url = 'http://www.pythonchallenge.com/pc/def/equality.html'
response = request.urlopen(url)
content = response.read()
hc = HandleComment()
hc.feed(str(content, 'utf-8'))
hc.close()
輸出結(jié)果如下:
linkedlist
替換原始URL中的equality
煞檩,得到URL:http://www.pythonchallenge.com/pc/def/linkedlist.html
,輸入該URL到瀏覽器救湖,顯示字符串linkedlist.php
暖庄,則最終獲得答案鏈接: http://www.pythonchallenge.com/pc/def/linkedlist.php
犯眠。