Мне нужно извлечь информацию со следующей веб-страницы с помощью Python 3: http://www.homefinance.nl/english/international-interest-rates/libor/libor-interest-rates-gbp.asp
Загрузка с использованием urllib.request выглядит нормально, но удивительно, когда я анализирую html-файл с моим классом HTMLParser,кажется, что синтаксический анализ останавливается в середине мета-тегов, без объяснения причин.
Это мой код:
import urllib.request
from html.parser import HTMLParser
def downloadLIBOR():
html_file = urllib.request.urlopen("http://www.homefinance.nl/english/international-interest-rates/libor/libor-interest-rates-gbp.asp")
return html_file
class tmpHTMLParser(HTMLParser):
def __init__(self):
self._libor = "0.81625 %"
self._stack = []
self._properStack = []
super().__init__()
def handle_starttag(self, tag, attrs):
print("starttag " + str(tag))
print(self.get_starttag_text())
self._stack.append(tag)
def handle_startendtag(self, tag, attrs):
print("startendtag")
def unknown_decl(self, data):
print("unknown_decl")
def handle_endtag(self, tag):
print("endtag " + str(tag))
self._stack.pop()
def _buildProperStack(webpage):
"""dev tool: return the stack leading to the libor rate libor into the webpage webpage."""
parser = tmpHTMLParser()
parser.feed(webpage)
if __name__ == "__main__":
webpage = downloadLIBOR()
print("download done")
html = str(webpage.read())
_buildProperStack(html)
exit(0)