亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶有簡單 html dom 解析器的垃圾 Javascript 和 Css 代碼

帶有簡單 html dom 解析器的垃圾 Javascript 和 Css 代碼

慕容森 2023-10-30 20:41:58
我正在使用簡單的 html dom 解析器來解析 php 的鏈接。下面是我正在使用的 url 和 php 代碼。網址:https://homeshopping.pk/products/-Imported-Stretchable-Tights-For-Women--Pack-Of-3-.htmlPHP 腳本:$html = file_get_html('https://homeshopping.pk/products/-Imported-Stretchable-Tights-For-Women--Pack-Of-3-.html');foreach($html->find('div#ProductDescription_Tab') as $description){    $comments = $description->find('.hsn_comments', 0);       $comments->outertext = '';      print $description->outertext ;}問題是,運行腳本后,我得到了我想要的前端,但查看頁面源代碼會顯示大量 javascript 和 css 垃圾代碼??梢詥幔课也荒苤猾@取 html 標簽而不需要任何額外的 css 或 javascript 代碼嗎?下面是我的 php 腳本運行腳本后查看頁面源的圖像。https://i.stack.imgur.com/78X6z.jpg
查看完整描述

1 回答

?
牛魔王的故事

TA貢獻1830條經驗 獲得超3個贊

如果您使用的是最新版本的 simpleHTMLDom,則可以使用該remove()功能。這是基于您現有代碼的示例代碼


$html = file_get_html('https://homeshopping.pk/products/-Imported-Stretchable-Tights-For-Women--Pack-Of-3-.html');


foreach($html->find('div#ProductDescription_Tab') as $description)

{

    $comments = $description->find('.hsn_comments', 0); 

      $comments->outertext = ''; 

    //remove div with script 

    $description->find('div#flix-minisite',0)->remove();

    $description->find('div#flix-inpage',0)->remove();


    //will remove all <script> tags

    foreach($description->find('script') as $s) $s->remove();


    //wil remove all <style> tags

    foreach($description->find('style') as $s) $s->remove();

     echo $description->innertext ;


}


查看完整回答
反對 回復 2023-10-30
  • 1 回答
  • 0 關注
  • 148 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號