PHP Curl İle HepsiBurada.com'dan Ürün Yorumlarını Çekme ve APİ Olarak Hizmete Açma

Konu

#1
index.php Dosyamız

PHP Kod:
<?php
include "class/class.functions.php";
include 
"class/hepsiburada.class.php";
$jsonArray = array(); // array değişkenimiz bunu en alta json objesine çevireceğiz. 
$jsonArray["hata"] = FALSE// Başlangıçta hata yok olarak kabul edelim. 

$_code 200// HTTP Ok olarak durumu kabul edelim. 

// üye ekleme kısmı burada olacak. CREATE İşlemi 
if($_SERVER['REQUEST_METHOD'] == "GET") {

    // üye bilgisi listeleme burada olacak. GET işlemi 
    
if(isset($_GET["link"]) && !empty(trim($_GET["link"])) && isset($_GET["comment"])) {
        
$jsonArray["detay"] = HepsiBurada::DetayHepsiBurada($_GET["link"],$_GET["comment"]);
        
$_code 200;
    }else {
        
$_code 400;
        
$jsonArray["hata"] = TRUE// bir hata olduğu bildirilsin.
        $jsonArray["hataMesaj"] = "Link and Comment is empty"// Hatanın neden kaynaklı olduğu belirtilsin.
    }
}else {
    
$_code 406;
    
$jsonArray["hata"] = TRUE;
    
$jsonArray["hataMesaj"] = "Geçersiz method!";
}


SetHeader($_code);
$jsonArray[$_code] = HttpStatus($_code);
echo 
json_encode($jsonArray);
?>
class.functions.php Dosyamız

PHP Kod:
<?php
// HTTP durum kodlarını getiren fonksiyonumuz. 
function HttpStatus($code) {
 
$status = array(
        100 => 'Continue',  
        101 
=> 'Switching Protocols',  
        200 
=> 'OK',
        201 => 'Created',  
        202 
=> 'Accepted',  
        203 
=> 'Non-Authoritative Information',  
        204 
=> 'No Content',  
        205 
=> 'Reset Content',  
        206 
=> 'Partial Content',  
        300 
=> 'Multiple Choices',  
        301 
=> 'Moved Permanently',  
        302 
=> 'Found',  
        303 
=> 'See Other',  
        304 
=> 'Not Modified',  
        305 
=> 'Use Proxy',  
        306 
=> '(Unused)',  
        307 
=> 'Temporary Redirect',  
        400 
=> 'Bad Request',  
        401 
=> 'Unauthorized',  
        402 
=> 'Payment Required',  
        403 
=> 'Forbidden',  
        404 
=> 'Not Found',  
        405 
=> 'Method Not Allowed',  
        406 
=> 'Not Acceptable',  
        407 
=> 'Proxy Authentication Required',  
        408 
=> 'Request Timeout',  
        409 
=> 'Conflict',  
        410 
=> 'Gone',  
        411 
=> 'Length Required',  
        412 
=> 'Precondition Failed',  
        413 
=> 'Request Entity Too Large',  
        414 
=> 'Request-URI Too Long',  
        415 
=> 'Unsupported Media Type',  
        416 
=> 'Requested Range Not Satisfiable',  
        417 
=> 'Expectation Failed',  
        500 
=> 'Internal Server Error',  
        501 
=> 'Not Implemented',  
        502 
=> 'Bad Gateway',  
        503 
=> 'Service Unavailable',  
        504 
=> 'Gateway Timeout',  
        505 
=> 'HTTP Version Not Supported');

    return $status[$code] ? $status[$code] : $status[500];
}
 
// Header ayarlama fonksiyonu 
function SetHeader($code){
    header("HTTP/1.1 ".$code." ".HttpStatus($code));
    header("Content-Type: application/json; charset=utf-8");
}
 
?>
hepsiburada.class.php Dosyamız

PHP Kod:
<?php
class HepsiBurada
{
    static $data = array ();
    /**
     * Ürün yorumlarını listeler
     *
     * @param $url $commentCount
     * @return array
     */
    static function DetayHepsiBurada$url $yorumsayi '1')
    {
        try {
    
        if ( !empty($url) )
    
        {
    
            $x 0;
    
            $i 1;
    
            self::$data;
    
            while ($x $yorumsayi) {
    
                preg_match_all('/hepsiburada[.]com/'$url$urlcheck);
    
                if(empty($urlcheck[0]))
    
                {
    
                    return 'Girilen link yanlış';
    
                }
    
                $page '-yorumlari?sayfa=' $i;
    
                $open self::Curl($url.$page);
    
                if(!$open)
    
                {
    
                    return 'Curl Siteye Bağlanırken Bir Sorunla Karşılaştı Yada Yoruma Sahip Olmayan Bir Ürün Linki Girildi';
    
                }
    
                preg_match_all('/<p class="review-text" itemprop="description">(.*?)<\/p>/'$open$result);
    
                if(!$result[0])
    
                {
    
                    return 'Girilen adreste yorum bulunamadı';
    
                }
    
                for($j=0;$j<count($result[1]);$j++){

    
                    self::$data[] = array (
    
                        'description' => $result[1][$j],
    
                        'id' => $x
                        
);
    
                    $x++;
    
                    if($x == $yorumsayi)
    
                        break;
    
                }
    
                if($x==19):
    
                    $x=0;
    
                    $i++;
    
                endif;
    
            }
    
        }
    
    } catch(Exception $e) {
    
        return array('error' => 'Yorum çekerken bir hata oluştu','errordetay' => $e.message());
    
    }
        return self::$data;
    }
    /**
     * Curl Fonksiyonumuz
     */
    private function Curl$url$proxy NULL )
    {
        $options = array ( CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER => false,
            CURLOPT_ENCODING => "",
            CURLOPT_AUTOREFERER => true,
            CURLOPT_CONNECTTIMEOUT => 30,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_SSL_VERIFYPEER => false
        
);
        $ch curl_init("$url");
        curl_setopt_array$ch$options );
        $content curl_exec$ch );
        $err curl_errno$ch );
        $errmsg curl_error$ch );
        $header curl_getinfo$ch );
        curl_close$ch );
        $header'errno' ] = $err;
        $header'errmsg' ] = $errmsg;
        $header'content' ] = $content;
        return str_replace( array ( "\n""\r""\t" ), NULL$header'content' ] );
    }

Kullanıcak arkadaşlar herhangi bir sorunuz olduğu zaman buradan yorum atarak sorabilirsiniz.İyi çalışmalar dilerim.

Kullanımı : url.com?link=ürünlinki&comment=yorumsayısı
Son Düzenleme: 06-02-2020, 22:44, Düzenleyen: Burkay ARAÇ.
Cevapla
Cevapla
#3
Teşekkürler
EKLENTİ YAZMIYORUM, YAZMAYIN ARTIK.
Cevapla
Cevapla
#5
Teşekkürler
Cevapla
Cevapla
#7
Elinize Sağlık
Cevapla
#8
Teşekkürler
stywashere
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da
Task
Kayıt Ol
Discord Adresimize Katılın