Home >Backend Development >PHP Tutorial >Use PHP to grab the specified album pictures from Baidu Tieba_PHP tutorial
@set_time_limit(10);
//Tieba name
$tbname = "mugen";
//Album ID
$tid = "2124904411";
//Album page url template
$galleryurltpl = "http://tieba.baidu.com/photo/bw/picture/guide?kw=%s&tid=%s";
//Local directory
$savepath = "R:/images/";
//Post subfolder
$filedir = $savepath.$tid;
//Image file
$filenametpl = $filedir."/%s.jpg";
//Album page url
$galleryurl = sprintf($galleryurltpl, $tbname, $tid);
//Returned json data
$retjson = file_get_contents($galleryurl);
$retarray = json_decode($retjson, true);
//Picture list
$piclist = $retarray['data']['pic_list'];
//Does the directory exist
if(!is_dir($filedir))
mkdir($filedir);
foreach($piclist as $pic){
$pic_id = $pic['img']['original']['id'];
$url = "http://imgsrc.baidu.com/forum/pic/item/".$pic_id.".jpg";
$filename = sprintf($filenametpl, $pic_id);
//Download image
$imagebin = file_get_contents($url);
//Save image
file_put_contents($filename,$imagebin);
}
?>