parsers = []
+# Statistics by parser - successfully parsed HTML pages:
+# 4358 beautifulsoup
+# 4310 htmlparser
+# 4307 html5
+# 4250 lxml
+
try:
from . import bkmk_ph_beautifulsoup
except ImportError:
parsers.append(bkmk_ph_beautifulsoup.parse_html)
try:
- from . import bkmk_ph_lxml
+ from . import bkmk_ph_htmlparser
except ImportError:
pass
else:
- parsers.append(bkmk_ph_lxml.parse_html)
+ parsers.append(bkmk_ph_htmlparser.parse_html)
try:
- from . import bkmk_ph_htmlparser
+ from . import bkmk_ph_html5
except ImportError:
pass
else:
- parsers.append(bkmk_ph_htmlparser.parse_html)
+ parsers.append(bkmk_ph_html5.parse_html)
try:
- from . import bkmk_ph_html5
+ from . import bkmk_ph_lxml
except ImportError:
pass
else:
- parsers.append(bkmk_ph_html5.parse_html)
+ parsers.append(bkmk_ph_lxml.parse_html)
# ElementTidy often segfaults
#try:
charsets.remove(charset)
charsets.insert(0, charset)
+ #_parsers = []
for p in parsers:
parser = None
for c in charsets:
try:
parser = p(filename, c, log)
- except UnicodeEncodeError:
+ except UnicodeError:
pass
else:
- break
+ if parser:
+ if log: log(" Parser %s: ok" % p.__module__)
+ #_parsers.append(parser)
+ break
+ else:
+ if log: log(" Parser %s: fail" % p.__module__)
if parser:
break
- else:
- if log: log("Parser %s.%s failed, trying next one." % (p.__module__, p.__name__))
+ #if not _parsers:
if not parser:
- if log: log("All parser has failed.")
+ if log: log(" All parser has failed")
return None
- if log: log(" Using %s" % p.__module__)
+ #parser = _parsers[0]
+ if log: log(" Using %s" % parser.__module__)
converted_title = title = parser.title
if title and (not parser.charset):