PHP implements parsing web pages and downloading images to local

WBOY
Release: 2016-07-25 08:45:35
Original
1472 people have browsed it
  1. //error_reporting(0);//Close error reporting
  2. include_once("simple_html_dom.php");//Introduce the parsing library
  3. $url='http://www.w3cschool.cc /mongodb/mongodb-window-install.html';
  4. $html=file_get_html($url);
  5. while($url[strlen($url)-1]!='/')$url=substr($url, 0,-1);//Get the upper directory
  6. if(!is_dir($filepath)){mkdir($_SERVER['DOCUMENT_ROOT']."/imgtmp/",1);}//Create the directory
  7. foreach($ html->find('img') as $im)
  8. {
  9. $p=$im->src;
  10. if($p[0]=='/'||$p[0]==' \')$p=$url."..".$p;//Complete url
  11. file_put_contents("imgtmp/".md5(microtime()).".".substr($p,-3), file_get_contents($p));
  12. }
  13. ?>
Copy code

Download images, php


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!