Home > Backend Development > PHP Tutorial > The code to capture the specified album pictures from Baidu Tieba to local area

The code to capture the specified album pictures from Baidu Tieba to local area

WBOY
Release: 2016-07-25 08:51:10
Original
718 people have browsed it
For details, see http://qxblog.sinaapp.com/?p=95
  1. @set_time_limit(10);
  2. //Post bar name
  3. $tbname = "mugen";
  4. //Album ID
  5. $tid = "2124904411";
  6. //Album page url template
  7. $ galleryurltpl = "http://tieba.baidu.com/photo/bw/picture/guide?kw=%s&tid=%s";
  8. //Local directory
  9. $savepath = "R:/images/";
  10. / /Post subfolder
  11. $filedir = $savepath.$tid;
  12. //Picture files
  13. $filenametpl = $filedir."/%s.jpg";
  14. //Album page url
  15. $galleryurl = sprintf($galleryurltpl, $tbname, $tid);
  16. //Returned json data
  17. $retjson = file_get_contents($galleryurl);
  18. $retarray = json_decode($retjson, true);
  19. //Picture list
  20. $piclist = $retarray[' data']['pic_list'];
  21. //Whether the directory exists
  22. if(!is_dir($filedir))
  23. mkdir($filedir);
  24. foreach($piclist as $pic){
  25. $pic_id = $pic[ 'img']['original']['id'];
  26. $url = "http://imgsrc.baidu.com/forum/pic/item/".$pic_id.".jpg";
  27. $filename = sprintf($filenametpl, $pic_id);
  28. //Download the image
  29. $imagebin = file_get_contents($url);
  30. //Save the image
  31. file_put_contents($filename,$imagebin);
  32. }
  33. ?>
Copy code


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