import re
from sgmllib import SGMLParser, SGMLParseError
from BeautifulSoup import BeautifulSoup, CData
import re
from sgmllib import SGMLParser, SGMLParseError
from BeautifulSoup import BeautifulSoup, CData
class BadDeclParser(BeautifulSoup):
def parse_declaration(self, i):
"""Treat a bogus SGML declaration as raw data. Treat a CDATA
class BadDeclParser(BeautifulSoup):
def parse_declaration(self, i):
"""Treat a bogus SGML declaration as raw data. Treat a CDATA
root = _parse_html(html_text, charset)
if root is None:
return None
_charset = root.originalEncoding
root = _parse_html(html_text, charset)
if root is None:
return None
_charset = root.originalEncoding
- if _charset in ("ISO-8859-2", "windows-1252", "MacCyrillic"): # Replace default
+ if _charset in ("ISO-8859-2", "windows-1252", "MacCyrillic"):
+ # Replace with default and re-parse
_charset = DEFAULT_CHARSET
root = _parse_html(html_text, _charset)
if root is None:
_charset = DEFAULT_CHARSET
root = _parse_html(html_text, _charset)
if root is None:
return None
return HTMLParser(_charset, meta_charset, title, refresh, icon)
return None
return HTMLParser(_charset, meta_charset, title, refresh, icon)
def _find_contenttype(Tag):
return (Tag.name == "meta") and \
(Tag.get("http-equiv", '').lower() == "content-type")
def _find_contenttype(Tag):
return (Tag.name == "meta") and \
(Tag.get("http-equiv", '').lower() == "content-type")
def _find_refresh(Tag):
return (Tag.name == "meta") and \
(Tag.get("http-equiv", '').lower() == "refresh")
def _find_refresh(Tag):
return (Tag.name == "meta") and \
(Tag.get("http-equiv", '').lower() == "refresh")
def _find_icon(Tag):
return (Tag.name == "link") and \
(Tag.get("rel", '').lower() in ('icon', 'shortcut icon'))
def _find_icon(Tag):
return (Tag.name == "link") and \
(Tag.get("rel", '').lower() in ('icon', 'shortcut icon'))