示例#1
0
 def fromstring(cls, html):
     encoding = get_encodings_from_content(html)
     encoding = encoding and encoding[0] or None
     if not encoding:
         html = encodeValue(html)
         doc = lxml.html.fromstring(html)
     else:
         html = smart_str(html, encoding=encoding)
         parser = lxml.html.HTMLParser(encoding=encoding)
         doc = lxml.html.fromstring(html, parser=parser)
     return doc
示例#2
0
 def stringToNode(cls, html):
     html = encodeValue(html)
     return lxml.html.fromstring(html)
示例#3
0
 def fromstring(cls, html):
     html = encodeValue(html)
     doc = etree.parse(StringIO(html),
                       etree.HTMLParser(recover=True)).getroot()
     return doc
示例#4
0
 def fromstring(cls, html):
     from lxml.html import soupparser
     html = encodeValue(html)
     doc = soupparser.fromstring(html)
     return doc
示例#5
0
 def fromstring(self, html):
     from lxml.html import soupparser
     html = encodeValue(html)
     self.doc = soupparser.fromstring(html)
     return self.doc