Photobucket Crawler

05/17/2012 20:54 creαтιve'αrт#1
Hallo liebe elitepvpers* Community,

nachdem ein Freund ein Photobucket Thumbnail Crawler gecodet hat, habe ich mir gedacht - ich machs nun auch für Fotos. Ihr müsst aber euch im Klaren sein, dass die Fotos abgespeichert werden.

Info: Manchmal kommt ein 400er Bad Request error weil wir zu schnell requesten.

Hier der Code:
PHP Code:
<?php
/*
 *Author: Finn // creative'Art
 *Date: 2012-10-04
*/

error_reporting(0);
class 
Photobucket {
    public function 
__construct() {
        echo 
">> Photobucket.com Imagecrawler \r\n";
        while(
true)
            
$this->crawler();
    }
    
    public function 
crawler() {
        
$source $this->request();
        
        
preg_match_all('#pbthumburl="(.*?)" #'$source$images);
        
        
$anzahl count($images[1]);
        
        echo 
">> $anzahl Bilder gefunden!\r\n";
        
        for(
$i 0$i $anzahl$i++) {
            
$imagename md5(rand(1,1000));
            
            
$url str_replace('th_'''$images[1][$i]);
            
            
$download file_get_contents($url);
            
$fileinfo pathinfo($images[1][$i]);
            
            if(
strlen($download) > 10) {                
                
file_put_contents('bilder/'.$imagename.'.'.$fileinfo['extension'], $download);
            }
            
            
sleep(2);
            
            echo 
">> $i / $anzahl gedownloadet! \r";
        }
        
        if(
$i == 20) {
            
//echo ">> Fertig...                   \r\n";
        
} else {
            echo 
">> Fehler beim Crawlen!\r\n";
        }
    }
    
    public function 
request() {
        
$ch curl_init();
        
        
curl_setopt($chCURLOPT_URL'http://photobucket.com/recent/images/');
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
curl_setopt($chCURLOPT_HEADERfalse);
        
        
$data curl_exec($ch);
        
curl_close($ch);
        
        return 
$data;
    }
}

$crawler = new Photobucket();
?>

Einfach hochladen und per php5 crawler.php starten (benötigt php5-cli bei Linux). Wenn ihr unter Windows seid, dann installiert euch PHP (windows.php.net) und erstellt euch eine start.bat mit dem Inhalt:


Code:
@echo off
php crawler.php
pause
Mit freundlichen Grüßen,
creαтιve'αrт