PHP学习笔记。小技巧
来源:互联网 发布:qq代理公布软件 编辑:程序博客网 时间:2024/06/05 15:19
抓取百度贴吧指定相册图片到本地的代码
<?php 02 @set_time_limit(10); 03 //贴吧名称 04 $tbname = "mugen"; 05 //相册ID 06 $tid = "2124904411"; 07 //图册页url模版 08 $galleryurltpl = "http://tieba.baidu.com/photo/bw/picture/guide?kw=%s&tid=%s"; 09 //本地的目录 10 $savepath = "R:/images/"; 11 //帖子子文件夹 12 $filedir = $savepath.$tid; 13 //图片文件 14 $filenametpl = $filedir."/%s.jpg"; 15 //图册页url 16 $galleryurl = sprintf($galleryurltpl, $tbname, $tid); 17 18 //返回的json数据 19 $retjson = file_get_contents($galleryurl); 20 $retarray = json_decode($retjson, true); 21 //图片列表 22 $piclist = $retarray['data']['pic_list']; 23 24 //目录是否存在 25 if(!is_dir($filedir)) 26 mkdir($filedir); 27 foreach($piclist as $pic){ 28 $pic_id = $pic['img']['original']['id']; 29 $url = "http://imgsrc.baidu.com/forum/pic/item/".$pic_id.".jpg"; 30 $filename = sprintf($filenametpl, $pic_id); 31 //下载图片 32 $imagebin = file_get_contents($url); 33 //保存图片 34 file_put_contents($filename,$imagebin); 35 } 36 ?>
- PHP学习笔记。小技巧
- Qt学习笔记:小技巧
- php——学习笔记,数据类型和小例以及echo使用技巧
- 学习笔记:文件处理的小技巧
- MVC 3 学习笔记及小技巧
- Asp.Net 学习笔记 小技巧
- [Emacs学习笔记]一些小技巧
- EXCEL学习笔记——小技巧
- c++学习笔记(小技巧)
- PHP小技巧
- PHP 小技巧
- PHP优化小技巧
- php缓存小技巧
- PHP优化小技巧
- php 编程 小技巧
- PHP小技巧
- php小技巧
- php 小技巧
- Cache 优化(矩阵乘积为例)
- 新的篇章4
- Android的网络应用前篇
- Java Enum学习笔记
- PHP学习笔记。。环境快速搭建/等
- PHP学习笔记。小技巧
- php防止sql注入
- 网站建设
- he.jasper.JasperException: javax.el.PropertyNotFoundException: Property '0' not found on type com.jy
- MySql级联删除和更新
- MySQL5触发器教程
- Android核心基础(六)
- 疑问解决代码小记录
- Python的时间:秒和字符串之间的转换