【问题标题】:Remove script tag from parsed html with simple html dom parser使用简单的 html dom 解析器从解析的 html 中删除脚本标记
【发布时间】:2020-07-16 10:23:29
【问题描述】:

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

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


     echo $description->outertext;

}

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

【问题讨论】:

    标签: php parsing web-scraping xml-parsing html-parsing


    【解决方案1】:

    好吧,所以我发现自己只是使用 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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多