Skip to content

Instantly share code, notes, and snippets.

@halka
Created June 21, 2010 15:04
Show Gist options
  • Save halka/446974 to your computer and use it in GitHub Desktop.
Save halka/446974 to your computer and use it in GitHub Desktop.
twitpicから指定したユーザが投稿した画像をすべてダウンロードします.
<?php
/*
これがひつようです
http://simplehtmldom.sourceforge.net/
*/
//すごく時間がかかります.
include 'simple_html_dom.php';
$count=0;
$username=''; //取得したいユーザ名を入れてね!
$allpics=; //そのユーザの全画像数を入れてね!
$page=(int)ceil($allpics/20); //ページ数を計算
echo "username : $username\n";
echo "pictures : $allpics\n";
echo "all pages : $page\n";
echo "Now parsing page...\n";
mkdir("$username",0777);
//ページを解析して画像の詳細ページのアドレスを調べるよ!
for($i=1;$i<=$page;$i++)
{
$html = file_get_html("http://twitpic.com/photos/$username?page=$i");
$divimage=$html->find('div.profile-photo-img'); //jQueryっぽい感じでDOMツリーを見てます
foreach($divimage as $div)
{
foreach($div->find('a') as $element)
{
$list[$count]=$element->href;
$count++;
}
}
}
echo "Parse finished\n";
echo "Starting to download\n";
$files=0;
//調べたアドレスからフルサイズの画像をダウンロードするよ!
foreach($list as $entry)
{
$count=0;
$imagepage=file_get_html("http://twitpic.com$entry/full");
foreach($imagepage->find('img') as $element)
{
$image=$element->src;
if($count==1)
{
file_put_contents("$username".'/'.str_replace("/","",$entry).".jpg",file_get_contents($element->src));
$files++;
}
$count++;
}
}
echo "downloaded files : $files\n";
echo "Finished! enjoy!! it's join!\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment