Home >Backend Development >PHP Tutorial >Use PHP to grab the specified album pictures from Baidu Tieba_PHP tutorial

Use PHP to grab the specified album pictures from Baidu Tieba_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:17:30901browse

@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);
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371985.htmlTechArticle?php @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=%stid...
Statement:
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