• selenium获取html源代码


    • # 执行js得到整个HTML

        html = driver.execute_script("return document.documentElement.outerHTML")

    • 获得整个文档的HTML

        html = driver.find_element_by_xpath("//*").get_attribute("outerHTML")
        # 不要用 driver.page_source,那样得到的页面源码不标准

    • 获取单个元素具体的HTML源文件

        webElement.getAttribute("outerHTML")

    • 获取元素的所有属性
    Object[] attr = ((JavascriptExecutor)seleniumdriver).executeScript("return arguments[0].attributes);", webElement);

    String source=driver.findElement(By.xpath("/html/body/script[6]")).getAttribute("innerHTML");
    • 分隔的方法

    If we have this:

    <a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button"
    style="position: absolute; border-radius: 0px 0px 4px 4px;">
    <span class="ui-icon ui-icon-closethick">close</span></a>

    and we need to get all attributes of "a" which will be this:

    href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button"
        style="position: absolute; border-radius: 0px 0px 4px 4px;"

    We can use this code:

    webElement.getAttribute("outerHTML").split(">")[0]

    where webElement is "a".

    Or more precisely:

    String s = we.getAttribute("outerHTML");
    
    s = s.substring(2, s.indexOf(">"));
     
  • 相关阅读:
    主键为整型数据库设计
    raid1与raid5
    asp.net限时发送手机验证码
    利用jQuery与.ashx完成简单的Ajax
    Solr使用in语法查询
    Solr高效利用:Solr实现SQL的查询与统计
    lucene 的评分机制
    fastcgi配置
    安装elasticsearch及中文IK和近义词配置
    php多进程处理
  • 原文地址:https://www.cnblogs.com/hushaojun/p/5985673.html
Copyright © 2020-2023  润新知