php實現解析網頁并下載圖片到本地
<?php //error_reporting(0);//關閉錯誤報告 include_once("simple_html_dom.php");//引入解析庫 $url='http://www.w3cschool.cc/mongodb/mongodb-window-install.html'; $html=file_get_html($url); while($url[strlen($url)-1]!='/')$url=substr($url,0,-1);//獲得上層目錄 if(!is_dir($filepath)){mkdir($_SERVER['DOCUMENT_ROOT']."/imgtmp/",1);}//創建目錄 foreach($html->find('img') as $im) { $p=$im->src; if($p[0]=='/'||$p[0]=='\\')$p=$url."..".$p;//補全url file_put_contents("imgtmp/".md5(microtime()).".".substr($p,-3),file_get_contents($p)); } ?>
本文由用戶 ef4w 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!