]> git.phdru.name Git - bookmarks_db.git/blobdiff - parse_html/bkmk_ph_html5.py
Change parse_html to parse strings, not files
[bookmarks_db.git] / parse_html / bkmk_ph_html5.py
index 53109be72fd761f874a92723f0eb4d606c47b11f..6400d02c20b924b0d77e65709c9136ab1647d41e 100644 (file)
@@ -1,10 +1,11 @@
 """HTML Parser using html5
 
 This file is a part of Bookmarks database and Internet robot.
+
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2010-2013 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2010-2014 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 __all__ = ['parse_html']
@@ -14,12 +15,9 @@ from html5lib import HTMLParser as HTML5Parser
 from .bkmk_ph_util import HTMLParser
 
 
-def parse_html(filename, charset=None, log=None):
+def parse_html(html_text, charset=None, log=None):
     parser = HTML5Parser()
-    fp = open(filename)
-    parser._parse(fp, encoding=charset, parseMeta=bool(charset))
-    fp.close()
-    html_tree = parser.tree.getDocument()
+    html_tree = parser.parse(html_text, encoding=charset, parseMeta=bool(charset))
 
     for node in html_tree.childNodes:
         if (node.name == 'html') and (node.type != 3): # Skip DocType element