您的錯誤消息說,不存在任何元素代理。代理意味着該節點的缺少的C
表示。
使用c.__class__()
您嘗試調用_Element
類的構造函數。 LXML的文件說:
It is important to know that every proxy in lxml has a factory function that properly sets up C level members. Proxy objects must never be instantiated outside of that factory. For example, to instantiate an _Element object or its subclasses, you must always call its factory function::
cdef xmlNode* c_node
cdef _Document doc
cdef _Element element
...
element = _elementFactory(doc, c_node)
不使用工廠模式和傳遞c_node,構造函數將失敗,因爲斷言:
LXML/src目錄/ LXML/apihelpers.pxi:
cdef inline int _assertValidNode(_Element element) except -1:
assert element._c_node is not NULL, u"invalid Element proxy at %s" % id(element)