Using php to capture Baidu Post Bar and specifying album Pictures _ PHP Tutorial

Source: Internet
Author: User
Use php to capture Baidu posts and specify album images .? Php @ set_time_limit (10); post bar name $ tbnamemugen; album ID $ tid2124904411; Image album url template $ galleryurltpltieba. baidu. comphotobwpictureguide? Kw % stid

@ Set_time_limit (10 );
// Paste the name
$ Tbname = "mugen ";
// Album ID
$ Tids = "2124904411 ";
// Url template of the image album page
$ Galleryurltpl = "http://tieba.baidu.com/photo/bw/picture/guide? Kw = % s & tid = % s ";
// Local Directory
$ Savepath = "R:/images /";
// Post subfolders
$ Filedir = $ savepath. $ tid;
// Image file
$ Filenametpl = $ filedir. "/%s.jpg ";
// Url of the image album
$ Galleryurl = sprintf ($ galleryurltpl, $ tbname, $ tid );

// Return json data
$ Retjson = file_get_contents ($ galleryurl );
$ Retarray = json_decode ($ retjson, true );
// Image list
$ Piclist = $ retarray ['data'] ['Pic _ list'];

// Check whether the directory exists
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 the image
$ Imagebin = file_get_contents ($ url );
// Save the image
File_put_contents ($ filename, $ imagebin );
}
?>

Http://www.bkjia.com/PHPjc/371985.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/371985.htmlTechArticle? Php @ set_time_limit (10); // Post it NAME $ tbname = mugen; // album ID $ tid = 2124904411; // url template $ galleryurltpl = http://tieba.baidu.com/photo/bw/picture/guide? Kw = % stid...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.