我正在尝试扩展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)
任何想法如何正确执行?