扩展lxml.html.HtmlElement对象

时间:2019-04-30 11:36:40

标签: python html-parsing lxml

我正在尝试扩展lxml.html.HtmlElement的功能,但没有成功。我班的原型看起来像这样

class HtmlTree(HtmlElement):

   encoding = None

   @classmethod
   def from_body(html_body, encoding, base_url):
      tree = html.fromstring(
         html_body,
         parser=html.HTMLParser(encoding=encoding),
         base_url=base_url
      )

      o = cls()
      o.encoding = encoding

   # I do not know how to move tree into my object

   def tostring(self):
      html.tostring(self, encoding=self.encoding)

任何想法如何正确执行?

0 个答案:

没有答案