您现在的位置是:主页 > news > 哈尔滨住房和城乡建设厅官方网站/自制网站教程

哈尔滨住房和城乡建设厅官方网站/自制网站教程

admin2025/5/7 9:19:39news

简介哈尔滨住房和城乡建设厅官方网站,自制网站教程,腾讯邮箱企业邮箱登录,龙之向导外贸论坛思路: 1.找到一个页面 2.正则过滤所有的img 3.正则过滤出所有的src的属性 4.获取链接信息,写入文件 file_get_contents(), file_put_contents() 5.在cli模式下运行代码(浏览器运行可能内存爆掉,或运行超时) 代码: 1 <?php2 //过滤所有的img3 $url "http://ww…

哈尔滨住房和城乡建设厅官方网站,自制网站教程,腾讯邮箱企业邮箱登录,龙之向导外贸论坛思路: 1.找到一个页面 2.正则过滤所有的img 3.正则过滤出所有的src的属性 4.获取链接信息,写入文件 file_get_contents(), file_put_contents() 5.在cli模式下运行代码(浏览器运行可能内存爆掉,或运行超时) 代码: 1 <?php2 //过滤所有的img3 $url "http://ww…

思路:

1.找到一个页面

2.正则过滤所有的img

3.正则过滤出所有的src的属性

4.获取链接信息,写入文件 file_get_contents(), file_put_contents()

5.在cli模式下运行代码(浏览器运行可能内存爆掉,或运行超时)

代码:

 1 <?php
 2     //过滤所有的img
 3     $url = "http://www.ivsky.com/";
 4     $str = file_get_contents($url);
 5     $preg = '/<img[^>]*\/>/';
 6     preg_match_all($preg, $str, $matches);
 7     $matches = $matches[0];
 8 
 9     //获取src中的链接
10     $arr = [];
11     foreach($matches as $v){
12         $preg = '/http:\/\/.*.jpg/';
13         preg_match_all($preg, $v, $match);
14         $arr[] = $match[0][0];
15     }
16     //文件保存地址
17     $dir = 'E:/abs/img/';
18 
19     foreach($arr as $k => $v){
20         //图片名称
21         $name = $dir . $k . '.jpg';
22         //下载
23         download($name, $v);
24     }
25     function download($name, $url){
26         if(!is_dir(dirname($name))){
27             mkdir(dirname($name));
28         }
29         $str = file_get_contents($url);
30         file_put_contents($name, $str);
31         //输出一些东西,要不窗口一直黑着,感觉怪怪的
32         echo strlen($str);
33         echo "\n";
34     }

注:仅供学习,如果侵犯到某人权利请联系我我.

转载于:https://www.cnblogs.com/catcrazy/p/6412117.html