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_name | str | 读取 | 合格的标签名称(对于 HTML 元素使用大写)。 |
tag_name | str | 读取 | 合格的标签名称(大写,HTML 元素)。 |
local_name | str | 读取 | 限定名称的本地部分(小写)。 |
namespace_uri | `str | None` | 读取 |
style_sheets | "StyleSheetList" | 读取 | 适用于此元素文档的实时样式表列表。 |
prefix | `str | None` | 读取 |
id | str | 读取 | id 属性的值,如果不存在,则为 ''。 |
class_name | str | 读取 | class 属性的值,或 ''。 |
class_list | "DOMTokenList" | 读取 | 实时可变的 CSS 类令牌集合,由 class 属性支持。 |
dataset | "DOMStringMap" | 读取 | 实时字典式视图,展示元素的 data-* 自定义属性。 |
attributes | NamedNodeMap | 读取 | 此元素的 Attr 对象的有序映射。 |
children | HTMLCollection | 读取 | 仅包含 Element 类型子节点的实时 HTMLCollection。 |
first_element_child | `Element | None` | 读取 |
last_element_child | `Element | None` | 读取 |
next_element_sibling | `Element | None` | 读取 |
previous_element_sibling | `Element | None` | 读取 |
child_element_count | int | 读取 | Element 子元素的数量。 |
inner_html | str | 读写 | 所有子元素的序列化 HTML 内容(innerHTML)。 |
outer_html | str | 读写 | 此元素及其所有后代的序列化 HTML(outerHTML)。 |
text_content | `str | None` | 读写 |
style | "CSSStyleDeclaration" | 读取 | 此元素的内联样式,作为实时 CSSStyleDeclaration。 |
scroll_width | int | 读取 | 内容滚动宽度,以 CSS 像素为单位(stub: 0)。 |
scroll_height | int | 读取 | 内容滚动高度,以 CSS 像素为单位(stub: 0)。 |
client_width | int | 读取 | 内部宽度(包括内边距,不包括边框)(stub: 0)。 |
client_height | int | 读取 | 内部高度(包括内边距,不包括边框)(stub: 0)。 |
scroll_top | int | 读写 | 垂直滚动偏移量(单位为 CSS 像素)(stub: 0)。 |
scroll_left | int | 读写 | 水平滚动偏移量(单位为 CSS 像素)(stub: 0)。 |
offset_width | int | 读取 | 布局 border-box 宽度,以 CSS 像素为单位(stub: 0)。 |
offset_height | int | 读取 | 布局 border-box 高度,以 CSS 像素为单位(stub: 0)。 |
offset_top | int | 读取 | 相对于 offsetParent 的顶部偏移,以 CSS 像素为单位(stub: 0)。 |
offset_left | int | 读取 | 左偏移量相对于 offsetParent,单位为 CSS 像素(stub: 0)。 |
offset_parent | None | 读取 | 偏移父元素;在无头模式下始终为 None。 |
client_top | int | 读取 | 顶部 CSS 边框的宽度(像素);在无头模式下始终为 0。 |
client_left | int | 读取 | 左侧 CSS 边框的宽度(像素);在无头模式下始终为 0。 |
part | "DOMTokenList" | 读取 | 实时 DOMTokenList,反映元素的 part 属性。 |
shadow_root | `` | 读取 | 在无头模式下始终为 None。 |
slot | str | 读写 | 反映 slot 内容属性 (DOM §4.2.3)。 |
assigned_slot | `` | 读取 | 在无头模式下始终 None。 |
node_type | int | 读取 | 来自 NodeType 的整数节点类型常量。 |
node_value | `str | None` | 读写 |
parent_node | `Node | None` | 读取 |
parent_element | `Element | None` | 读取 |
is_connected | bool | 读取 | 该节点是否是文档节点树的一部分(WHATWG DOM §4.4)。 |
owner_document | `Document | None` | 读取 |
child_nodes | NodeList | 读取 | 所有子节点的实时 NodeList。 |
first_child | `Node | None` | 读取 |
last_child | `Node | None` | 读取 |
previous_sibling | `Node | None` | 读取 |
next_sibling | `Node | None` | 读取 |
方法
| 签名 | 描述 |
|---|---|
| `init(local_name: str, namespace_uri: str | None, 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: “Element | None”)→“Element |
get_attribute(name: str) → `str | None` |
set_attribute(name: str, value: str) | 设置属性 name to value,如果不存在则创建。 |
remove_attribute(name: str) | 移除属性 name. |
has_attribute(name: str) → bool | Return True 如果属性 name 存在于此元素上。 |
get_attribute_node(name: str) → `“Attr | None”` |
set_attribute_node(attr: "Attr") → `“Attr | None”` |
remove_attribute_node(attr: "Attr") → "Attr" | Remove attr 从此元素的属性集合中获取并返回它。 |
| `get_attribute_node_ns(namespace_uri: str | None, local_name: str)→“Attr |
set_attribute_node_ns(attr: "Attr") → `“Attr | None”` |
| `remove_attribute_node_ns(namespace_uri: str | None, local_name: str)→“Attr”` |
| `get_attribute_ns(namespace_uri: str | None, local_name: str)→str |
| `set_attribute_ns(namespace_uri: str | None, qualified_name: str, value: str)` |
| `has_attribute_ns(namespace_uri: str | None, local_name: str)→bool` |
| `remove_attribute_ns(namespace_uri: str | None, local_name: str)` |
| `toggle_attribute(name: str, force: bool | None)→bool` |
get_attribute_names() → list[str] | 返回所有属性的限定名称,按集合顺序。 |
has_attributes() → bool | 当此元素具有一个或多个属性时,返回 True。 |
| `scroll_into_view(arg: bool | dict |
| `scroll(x_or_options: float | dict |
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: “dict | None”)` |
| `check_visibility(options: “dict | None”)→bool` |
query_selector(selector: str) → `Element | None` |
query_selector_all(selector: str) → NodeList | 返回所有匹配元素的静态 NodeList selector. |
matches(selector: str) → bool | Return True 如果此元素匹配 CSS selector. |
webkit_matches_selector(selector: str) → bool | 浏览器兼容别名,针对 :meth:matches。 |
closest(selector: str) → `“Element | None”` |
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: “dict | None”)` |
get_root_node(composed: bool) → "Node" | 返回节点树的根节点。 |
has_child_nodes() → bool | 返回此节点是否至少有一个直接子节点。 |
| `lookup_namespace_uri(prefix: str | None)→str |
| `lookup_prefix(namespace_uri: str | None)→str |
| `is_default_namespace(namespace_uri: str | None)→bool` |
| `is_supported(feature: str, version: str | None)→bool` |
| `get_feature(feature: str, version: str | None)→object |
| `set_user_data(key: str, data: object | None, handler: object |
get_user_data(key: str) → `object | None` |
append_child(node: Node) → Node | Append node 作为此节点的最后一个子节点。 |
| `insert_before(node: Node, reference: Node | None)→Node` |
remove_child(node: Node) → Node | Remove node 从子列表中取出并返回它。 |
replace_child(new_child: Node, old_child: Node) → Node | Replace old_child with new_child. |
clone_node(deep: bool) → Node | 返回此节点的副本。 |
normalize() | 将此节点及其整个子树转换为标准化形式。 |
| `contains(other: Node | None)→bool` |
compare_document_position(other: "Node") → int | 返回描述位置的位掩码 other 相对于此节点。 |
| `is_equal_node(other: Node | None)→bool` |
| `is_same_node(other_node: Node | None)→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") → bool | Dispatch event 通过祖先树。 |