繁体   English   中英

使用简单的 html dom 解析器从解析的 html 中删除脚本标签

[英]Remove script tag from parsed html with simple html dom parser

我正在使用简单的 html dom 解析器和 php 使用以下代码解析链接。

foreach($html->find('div#ProductDescription_Tab') as $description)
{
    $comments = $description->find('.hsn_comments', 0); 
      $comments->outertext = ''; 


     echo $description->outertext;

}

这给了我解析的数据以及 javascript “脚本”标签。 如何删除这些脚本标签?

好的,所以我发现自己只需使用 Advanced Html Dom 库,它与简单的 html dom 完全兼容,通过使用它,您将获得更多控制权。 从解析的 html 中删除您想要的内容非常简单。 对于前。

//to remove script tag
$scripts = $description->find('script')->remove;

//to remove css style tag
$style = $description->find('style')->remove;

// to remove a div with class name findify-element
$findify = $description->find('div.findify-element')->remove;

https://sourceforge.net/projects/advancedhtmldom/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM