parsers = []
-# Statistics by parser - successfully parsed HTML pages:
-# 4358 beautifulsoup
-# 4310 htmlparser
-# 4307 html5
-# 4250 lxml
-
try:
from . import bkmk_ph_beautifulsoup
except ImportError:
return ''.join(output)
+import os
+BKMK_DEBUG_HTML_PARSERS = os.environ.get("BKMK_DEBUG_HTML_PARSERS")
+
def parse_html(filename, charset=None, log=None):
if not parsers:
return None
charsets.remove(charset)
charsets.insert(0, charset)
- #_parsers = []
+ if BKMK_DEBUG_HTML_PARSERS:
+ _parsers = []
for p in parsers:
parser = None
for c in charsets:
pass
else:
if parser:
- #if log: log(" Parser %s: ok" % p.__module__)
- #_parsers.append(parser)
+ if BKMK_DEBUG_HTML_PARSERS:
+ if log: log(" Parser %s: ok" % p.__module__)
+ _parsers.append((p, parser))
break
else:
if log: log(" Parser %s: fail" % p.__module__)
- if parser:
+ if not BKMK_DEBUG_HTML_PARSERS and parser:
break
- #if not _parsers:
- if not parser:
+ if BKMK_DEBUG_HTML_PARSERS:
+ if not _parsers:
+ if log: log(" All parsers have failed")
+ return None
+ elif not parser:
if log: log(" All parsers have failed")
return None
- #parser = _parsers[0]
+ if BKMK_DEBUG_HTML_PARSERS:
+ p, parser = _parsers[0]
if log: log(" Using %s" % p.__module__)
converted_title = title = parser.title