简体   繁体   English

装饰lxml.etree._Element方法

[英]decorate lxml.etree._Element methods

I tried to decorate/override/patch the 'get' , 'text' , and 'findtext' methods of lxml.etree._Element , but it seems like it's impossible to achieve, as all the attributes are read-only, probably because it's not written in python. 我试图装饰/覆盖/修补“得”,“ 文本”“FINDTEXT” lxml.etree._Element的方法,但现在看来似乎是不可能实现的,因为所有的属性是只读的,可能是因为它是不是用python编写的。 Is there a way to decorate those methods? 有没有办法装饰这些方法? Thanks for any suggestions.. 感谢您的任何建议。

After reading the comments, I listened to the suggestion to use unicode everywhere, and encode to string just when outputting the data. 阅读注释后,我听了有关在各处使用unicode的建议,并在输出数据时将其编码为字符串。 Thanks for that, however I was curious after all to accomplish the task I wanted anyway, so here's what I've came up with, an lxml._Element class wrapper: 为此,尽管如此,我还是很好奇,无论如何我还是想完成我想要的任务,所以这就是我想出的一个lxml._Element类包装器:

https://github.com/integricho/lxmlproxy https://github.com/integricho/lxmlproxy

Maybe someone else will find it useful for something after all, as I did not find other orthodox solutions. 毕竟,有人可能会发现它对某些事情有用,因为我没有找到其他正统的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析lxml.etree._Element内容 - Parsing lxml.etree._Element contents 从lxml.etree._Element获取价值 - Get value from lxml.etree._Element python lxml.etree._Element 到 JSON 或 dict - python lxml.etree._Element to JSON or dict LXML/Python - 遍历 lxml.etree._Element 列表 - LXML/Python - Looping over a list of lxml.etree._Element python lxml 3.3.5 - 加载代码时出错 - “ValueError:lxml.etree._Element的大小错误,请尝试重新编译” - python lxml 3.3.5 - error on loading code - “ValueError: lxml.etree._Element has the wrong size, try recompiling” 令人难以置信的基本lxml问题:获取lxml.etree._Element的HTML /字符串内容? - Incredibly basic lxml questions: getting HTML/string content of lxml.etree._Element? lxml: cssselect(): AttributeError: 'lxml.etree._Element' 对象没有属性 'cssselect' - lxml: cssselect(): AttributeError: 'lxml.etree._Element' object has no attribute 'cssselect' 如何从zeep python库解析soap Fault.detail(lxml.etree._Element) - How parse soap Fault.detail(lxml.etree._Element) from zeep python library 真的很奇怪……无法设置内置/扩展类型“lxml.etree._Element”的属性 - Really weird… can't set attributes of built-in/extension type 'lxml.etree._Element' lxml.etree iterparse()和完全解析元素 - lxml.etree iterparse() and parsing element completely
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM