X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fparse_html_beautifulsoup.py;h=c8e8f5db54af91c96a439584d09ade66b094de46;hb=5c1c16d3e1a5fdf4ea1ecc6c31f5e4c6a4240bed;hp=4f395a16507e58d5e9a600de00b9056cb2aeb94b;hpb=d2499bf060be42a28feebde2e8bded52504ced95;p=bookmarks_db.git diff --git a/Robots/parse_html_beautifulsoup.py b/Robots/parse_html_beautifulsoup.py index 4f395a1..c8e8f5d 100644 --- a/Robots/parse_html_beautifulsoup.py +++ b/Robots/parse_html_beautifulsoup.py @@ -4,10 +4,11 @@ Written by BroytMann. Copyright (C) 2007 PhiloSoft Design """ +from HTMLParser import HTMLParser from BeautifulSoup import BeautifulSoup -class DummyParser(object): +class BSoupParser(HTMLParser): def __init__(self, charset, meta, title, refresh, icon): object.__init__(self) self.charset = charset @@ -16,14 +17,15 @@ class DummyParser(object): self.refresh = refresh self.icon = icon + def parse_html(filename, charset=None): infile = open(filename, 'r') root = BeautifulSoup(infile, fromEncoding=charset) infile.close() - charset = root.originalEncoding + _charset = root.originalEncoding try: - title = root.html.head.title.string.encode(charset) + title = root.html.head.title.string.encode(_charset) except AttributeError: title = '' @@ -47,8 +49,7 @@ def parse_html(filename, charset=None): else: icon = None - parser = DummyParser(charset, False, title, refresh, icon) - return parser + return BSoupParser(_charset, _charset == charset, title, refresh, icon) def _find_refresh(Tag): return (Tag.name == "meta") and \