簡體   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