zoukankan      html  css  js  c++  java
  • php_cawler_html嵌套标签清洗

    主要处理 嵌套 div,正则无法很好的处理清洗 
    比如文本: 想要移除 class =quizPutTag 的div  ,内部可能嵌套的还有未知层级的div【前提是html文本段是闭合标签的】
    这是<div>test<div class="quizPutTag">test</div><div class="quizPutTag">H<sub>2</sub>C<sub>2</sub>O<sub>4</sub>•2H<sub>2</sub>O<span dealflag="1" class="MathJye" mathtag="math" style="whiteSpace:nowrap;wordSpacing:normal;wordWrap:normal"><table cellpadding="-1" cellspacing="-1" style="margin-right:1px"><tbody><tr><td style="border-bottom:1px solid black;padding-bottom:1px;font-size:90%"><table style="margin-right: 1px" cellspacing="-1" cellpadding="-1"><tbody><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td style="font-size: 90%"><div style="border-top:1px solid black;line-height:1px">.</div></td></tr></tbody></table></td></tr><tr><td>&nbsp;</td></tr></tbody></table></span>CO↑+CO<sub>2</sub>↑+3H<sub>2</sub>O↑</div>保留的</div>
    实现code

    <?php
       include "./simple_html_dom.php";
       $output="";
       $input=fgets(fopen($argv[1],'r'));
       echo $input."
    
    ";
       $html = new simple_html_dom();
       $html->load('<html><body>'.$input.'</body></html>');
       $divsq = $html->find('div.quizPutTag');
       $divsa = $html->find('div.sanwser');
       $output=str_replace($divsq,'___',$input);
       $output=str_replace($divsa,'',$output);
       echo $divs[0]."
    ";
       echo $html."
    ";
       $html->clear();
       echo $output."
    ";
    
    ?>

    simple_html_dom.php

  • 相关阅读:
    (转)十分钟搞定CSS选择器
    (转)我所理解的OOP——UML六种关系
    闲话:你今天OO了吗?
    oledb方式读取excel文件
    (转)asp.net 高质量缩略图
    (转载)重温SQL——行转列,列转行
    第九讲,资源表解析
    第八讲,TLS表(线程局部存储)
    第七讲,重定位表
    第六讲,导出表
  • 原文地址:https://www.cnblogs.com/cphmvp/p/4728139.html
Copyright © 2011-2022 走看看