在div简单的html dom中跳过div

时间:2017-02-25 09:31:13

标签: dom simple-html-dom

我想从中抓取数据的页面包含以下元素

<div class="content">
 <p>I want this</p>
 <p>I want this</p>
 <div class="row">
   <p>I do not want this</p>
   <p>I do not want this</p>

 </div>
</div>

我不想要<div class="row">中的段落 这是我到目前为止所尝试的。似乎无法正常工作

foreach ($sample_html->find('div[class=entry-content]') as $content) {

                foreach($content->find('div[class=row]') as $row){

                    foreach ($row->find('p') as $skip) {

                        $skip->outertext = '';
                    }
                }

                foreach($content->find('p') as $paragraph){

                    //echo $paragraph;
                    $paragraphs .= '<p>'.$paragraph->innertext.'</p>';
                    echo $paragraphs;
                }


            }

1 个答案:

答案 0 :(得分:0)

更改

 $skip->outertext = '';

 $skip->innertext= '';