diff options
-rw-r--r-- | BeautifulSoup.py | 10 | ||||
-rw-r--r-- | lxml_builder.py | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/BeautifulSoup.py b/BeautifulSoup.py index 99ce460..aceb6d3 100644 --- a/BeautifulSoup.py +++ b/BeautifulSoup.py @@ -509,6 +509,8 @@ class Tag(PageElement, Entities): self.isSelfClosing = builder.isSelfClosingTag(name) if attrs == None: attrs = [] + if isinstance(attrs, types.DictType): + self.attrMap = attrs self.attrs = attrs self.contents = [] self.setup(parent, previous) @@ -523,8 +525,10 @@ class Tag(PageElement, Entities): if val is None: return kval return (k, re.sub("&(#\d+|#x[0-9a-fA-F]+|\w+);", convert_one, val)) - - self.attrs = map(convert, self.attrs) + if isinstance(attrs, types.DictType): + self.attrs = [convert(kv) for kv in attrs.items()] + else: + self.attrs = map(convert, attrs) def get(self, key, default=None): """Returns the value of the 'key' attribute for the tag, or @@ -1660,6 +1664,8 @@ class BeautifulSoup(BeautifulStoneSoup): def _defaultBuilder(self): return HTMLParserBuilder() +class ICantBelieveItsBeautifulSoup(BeautifulStoneSoup): + pass class StopParsing(Exception): pass diff --git a/lxml_builder.py b/lxml_builder.py index 16c60f4..77e2f98 100644 --- a/lxml_builder.py +++ b/lxml_builder.py @@ -3,7 +3,7 @@ from BeautifulSoup import TreeBuilder, Comment class LXMLBuilder(TreeBuilder): - def __init__(self, parser_class=etree.XMLParser, self_closing_tags=[]): + def __init__(self, parser_class=etree.HTMLParser, self_closing_tags=[]): self.parser = parser_class(target=self) self.self_closing_tags = self_closing_tags self.soup = None |