帮助中心
如何获取网页上指定元素内的html内容?

在进行元素操作时,往往需要获取元素内的html内容,您可以通过以下函数实现。

  1. 调用attachWebPageByUrl函数获取标签页对象。
  2. 调用findElement函数获取网页中的元素。
  3. 调用getAttribute函数获取目标元素的属性,其中设置参数为outerHTML,即为获取指定元素内的html内容。
    函数示例
from . import Resource, print
from Cube.UIAutomation import Window,Element,WebPage


def main():
    command_collect_func()
    pass


def command_collect_func():
    wp = WebPage.attachWebPageByUrl(browserType=1,url='https://www.baidu.com/')
    a = wp.findElement("本地元素库&INPUT - su").getAttribute('outerHTML')
    print(a)
1
2
3
4
5
6
7
8
9
10
11
12
13

运行结果


网页元素信息


最近更新时间: { "value": "2022-10-18", "effect": true }