【问题标题】:Grabbing hidden code (Using PHP Simple HTML DOM Parser)抓取隐藏代码(使用 PHP Simple HTML DOM Parser)
【发布时间】:2015-01-14 14:33:06
【问题描述】:

我有以下 HTML 代码。我需要抓取 div 容器中包含的代码,但问题是使用 PHP Simple HTML DOM Parser 解析 HTML 我无法抓取它,因为 aria-hidden 是真的。我怎样才能得到它?

<div class="ui-collapsible-content"  aria-hidden="true">
text here
</div>

【问题讨论】:

    标签: php html parsing html-parsing


    【解决方案1】:

    您的问题与aria-hidden 属性无关。无论元素是否隐藏以及是否具有任何属性,查找元素都有效。

    <?php
    
    require_once "./simple_html_dom.php";
    
    $html = '<div class="ui-collapsible-content" aria-hidden="true">text here</div><div class="bye">visible text</div>';
    $html = str_get_html($html);
    
    echo $html->find('.ui-collapsible-content', 0)->plaintext; // text here
    echo "\n";
    echo $html->find('.bye', 0)->plaintext; // visible text
    echo "\n";
    

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 2011-09-23
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 2012-08-12
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多