ホームページ  >  記事  >  バックエンド開発  >  PHP を使用して Baidu Tieba から指定されたアルバム写真を取得する_PHP チュートリアル

PHP を使用して Baidu Tieba から指定されたアルバム写真を取得する_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-20 11:17:30837ブラウズ

@set_time_limit(10);
//ティバの名前
$tbname = "ムゲン";
//アルバムID
$tid = "2124904411";
//アルバムページのURLテンプレート
$galleryurltpl = "http://tieba.baidu.com/photo/bw/picture/guide?kw=%s&tid=%s";
//ローカルディレクトリ
$savepath = "R:/images/";
//サブフォルダーを投稿します
$filedir = $savepath.$tid;
//画像ファイル
$filenametpl = $filedir."/%s.jpg";
//アルバムページのURL
$galleryurl = sprintf($galleryurltpl, $tbname, $tid);

//返されたjsonデータ
$retjson = file_get_contents($galleryurl);
$retarray = json_decode($retjson, true);
//画像リスト
$piclist = $retarray['data']['pic_list'];

//ディレクトリは存在しますか? 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);
//写真をダウンロードする
$imagebin = ファイル_get_contents($url); //画像を保存します
file_put_contents($filename,$imagebin);
}
?>

http://www.bkjia.com/PHPjc/371985.html

tru​​ehttp://www.bkjia.com/PHPjc/371985.html技術記事 ?php @set_time_limit(10); //Tieba 名 $tbname = mugen; //アルバム ID $tid = 2124904411; //アルバム ページ URL テンプレート $galleryurltpl = http://tieba.baidu.com/photo/bw/picture /guide?kw=%stid...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。