Element

Element

概述

Element 是 Aspose.Html FOSS for Python 中的一个类。继承自:Node。

一个 HTML 或 XML 元素节点。

此类提供 72 个方法,用于在 Python 程序中操作 Element 对象。可用的方法包括:__init__、add_event_listener、after、append、append_child、attach_shadow、before、check_visibility、clone_node、closest、compare_document_position、contains,以及另外 60 个方法。所有公共成员在安装 Aspose.Html FOSS for Python 包后,可供任何 Python 应用程序访问。属性:assigned_slot、attributes、child_element_count、child_nodes、children、class_list,以及另外 43 项。

属性

名称类型访问描述
node_namestr读取合格的标签名称(对于 HTML 元素使用大写)。
tag_namestr读取合格的标签名称(大写,HTML 元素)。
local_namestr读取限定名称的本地部分(小写)。
namespace_uri`strNone`读取
style_sheets"StyleSheetList"读取适用于此元素文档的实时样式表列表。
prefix`strNone`读取
idstr读取id 属性的值,如果不存在,则为 ''。
class_namestr读取class 属性的值,或 ''。
class_list"DOMTokenList"读取实时可变的 CSS 类令牌集合,由 class 属性支持。
dataset"DOMStringMap"读取实时字典式视图,展示元素的 data-* 自定义属性。
attributesNamedNodeMap读取此元素的 Attr 对象的有序映射。
childrenHTMLCollection读取仅包含 Element 类型子节点的实时 HTMLCollection。
first_element_child`ElementNone`读取
last_element_child`ElementNone`读取
next_element_sibling`ElementNone`读取
previous_element_sibling`ElementNone`读取
child_element_countint读取Element 子元素的数量。
inner_htmlstr读写所有子元素的序列化 HTML 内容(innerHTML)。
outer_htmlstr读写此元素及其所有后代的序列化 HTML(outerHTML)。
text_content`strNone`读写
style"CSSStyleDeclaration"读取此元素的内联样式,作为实时 CSSStyleDeclaration。
scroll_widthint读取内容滚动宽度,以 CSS 像素为单位(stub: 0)。
scroll_heightint读取内容滚动高度,以 CSS 像素为单位(stub: 0)。
client_widthint读取内部宽度(包括内边距,不包括边框)(stub: 0)。
client_heightint读取内部高度(包括内边距,不包括边框)(stub: 0)。
scroll_topint读写垂直滚动偏移量(单位为 CSS 像素)(stub: 0)。
scroll_leftint读写水平滚动偏移量(单位为 CSS 像素)(stub: 0)。
offset_widthint读取布局 border-box 宽度,以 CSS 像素为单位(stub: 0)。
offset_heightint读取布局 border-box 高度,以 CSS 像素为单位(stub: 0)。
offset_topint读取相对于 offsetParent 的顶部偏移,以 CSS 像素为单位(stub: 0)。
offset_leftint读取左偏移量相对于 offsetParent,单位为 CSS 像素(stub: 0)。
offset_parentNone读取偏移父元素;在无头模式下始终为 None。
client_topint读取顶部 CSS 边框的宽度(像素);在无头模式下始终为 0。
client_leftint读取左侧 CSS 边框的宽度(像素);在无头模式下始终为 0。
part"DOMTokenList"读取实时 DOMTokenList,反映元素的 part 属性。
shadow_root``读取在无头模式下始终为 None。
slotstr读写反映 slot 内容属性 (DOM §4.2.3)。
assigned_slot``读取在无头模式下始终 None。
node_typeint读取来自 NodeType 的整数节点类型常量。
node_value`strNone`读写
parent_node`NodeNone`读取
parent_element`ElementNone`读取
is_connectedbool读取该节点是否是文档节点树的一部分(WHATWG DOM §4.4)。
owner_document`DocumentNone`读取
child_nodesNodeList读取所有子节点的实时 NodeList。
first_child`NodeNone`读取
last_child`NodeNone`读取
previous_sibling`NodeNone`读取
next_sibling`NodeNone`读取

方法

签名描述
`init(local_name: str, namespace_uri: strNone, prefix: str
get_computed_style() → "ComputedStyleDeclaration"返回此元素的第2阶段级联解析声明。
insert_adjacent_html(position: str, html: str)在此元素相对位置插入已解析的 HTML 标记。
insert_adjacent_text(position: str, text: str)在此元素相对位置插入一个文本节点。
`insert_adjacent_element(position: str, element: “ElementNone”)→“Element
get_attribute(name: str) → `strNone`
set_attribute(name: str, value: str)设置属性 name to value,如果不存在则创建。
remove_attribute(name: str)移除属性 name.
has_attribute(name: str) → boolReturn True 如果属性 name 存在于此元素上。
get_attribute_node(name: str) → `“AttrNone”`
set_attribute_node(attr: "Attr") → `“AttrNone”`
remove_attribute_node(attr: "Attr") → "Attr"Remove attr 从此元素的属性集合中获取并返回它。
`get_attribute_node_ns(namespace_uri: strNone, local_name: str)→“Attr
set_attribute_node_ns(attr: "Attr") → `“AttrNone”`
`remove_attribute_node_ns(namespace_uri: strNone, local_name: str)→“Attr”`
`get_attribute_ns(namespace_uri: strNone, local_name: str)→str
`set_attribute_ns(namespace_uri: strNone, qualified_name: str, value: str)`
`has_attribute_ns(namespace_uri: strNone, local_name: str)→bool`
`remove_attribute_ns(namespace_uri: strNone, local_name: str)`
`toggle_attribute(name: str, force: boolNone)→bool`
get_attribute_names() → list[str]返回所有属性的限定名称,按集合顺序。
has_attributes() → bool当此元素具有一个或多个属性时,返回 True。
`scroll_into_view(arg: booldict
`scroll(x_or_options: floatdict
scroll_into_view_if_needed(center_if_needed: bool)如果此元素尚未可见,则将其滚动到可见位置(在无头模式下为无操作)。
set_pointer_capture(pointer_id: int)将此元素指定为给定指针的捕获目标(无操作)。
release_pointer_capture(pointer_id: int)释放给定指针 ID 的指针捕获(无操作)。
has_pointer_capture(pointer_id: int) → bool返回此元素是否对给定 ID 拥有指针捕获。
request_pointer_lock()请求将指针锁定到此元素(无操作)。
`request_fullscreen(options: “dictNone”)`
`check_visibility(options: “dictNone”)→bool`
query_selector(selector: str) → `ElementNone`
query_selector_all(selector: str) → NodeList返回所有匹配元素的静态 NodeList selector.
matches(selector: str) → boolReturn True 如果此元素匹配 CSS selector.
webkit_matches_selector(selector: str) → bool浏览器兼容别名,针对 :meth:matches。
closest(selector: str) → `“ElementNone”`
get_elements_by_tag_name(qualified_name: str) → HTMLCollection返回所有标签名称匹配的后代元素 qualified_name.
get_elements_by_class_name(class_names: str) → HTMLCollection返回所有包含给定所有类标记的后代元素。
filter_fn(el: "Element") → bool在此 Element 实例上调用 filter_fn(el)。
remove()将此元素从其父节点中移除。
before()Insert nodes 在其父节点中紧挨此元素之前。
after()Insert nodes 在其父元素中紧随此元素之后。
replace_with()用…替换此元素 nodes 在其父元素中。
prepend()Insert nodes 在此元素的第一个子元素之前。
append()Append nodes 作为此元素的最后子节点。
replace_children()删除所有子节点,然后追加 nodes 作为新的子节点。
get_bounding_client_rect() → "DOMRect"返回边界客户端矩形(全零存根)。
get_client_rects() → "DOMRectList"返回客户端矩形列表(在服务器端上下文中为空)。
get_animations() → list[object]返回此元素的活动动画(无头存根:始终为 [])。
`attach_shadow(init: “dictNone”)`
get_root_node(composed: bool) → "Node"返回节点树的根节点。
has_child_nodes() → bool返回此节点是否至少有一个直接子节点。
`lookup_namespace_uri(prefix: strNone)→str
`lookup_prefix(namespace_uri: strNone)→str
`is_default_namespace(namespace_uri: strNone)→bool`
`is_supported(feature: str, version: strNone)→bool`
`get_feature(feature: str, version: strNone)→object
`set_user_data(key: str, data: objectNone, handler: object
get_user_data(key: str) → `objectNone`
append_child(node: Node) → NodeAppend node 作为此节点的最后一个子节点。
`insert_before(node: Node, reference: NodeNone)→Node`
remove_child(node: Node) → NodeRemove node 从子列表中取出并返回它。
replace_child(new_child: Node, old_child: Node) → NodeReplace old_child with new_child.
clone_node(deep: bool) → Node返回此节点的副本。
normalize()将此节点及其整个子树转换为标准化形式。
`contains(other: NodeNone)→bool`
compare_document_position(other: "Node") → int返回描述位置的位掩码 other 相对于此节点。
`is_equal_node(other: NodeNone)→bool`
`is_same_node(other_node: NodeNone)→bool`
add_event_listener(type: str, listener: Callable, capture: bool, once: bool)Register listener 针对以下事件的 type.
remove_event_listener(type: str, listener: Callable, capture: bool)注销先前已注册的监听器。
dispatch_event(event: "Event") → boolDispatch event 通过祖先树。

另请参阅

 中文