چگونگی نمایش قسمتی از یک سایت در سایت دیگر

Pro Mind

تازه وارد
سلام بر استادان گرامی

اقا من می خوام یه قسمتی از یه سایتی را تو سایت خودم بزارم

قسمت اکران سینمای ایران و اکران سینمای جهان یا کل تب را میخوام تو سایت خودم بزارم به صورتی ک اطلاعات را از این سایت بگیره ولی با استایل وبسایت خودم



ممنون میشم راهنماییم کنید :D :D

 

Mohammad

مدیر انجمن
پرسنل مدیریت
من از این کد استفاده میکنم


کد:
<?php 
ini_set('max_execution_time', 300);
$scraper = new DOMScraper();
//address ro inja bede
$scraper->setSite('http://www.feebazar.ir/index.php')->setSource();


Class DOMScraper extends DOMDocument{
    public $site;
    private $source;
    private $dom;

    function __construct(){
        libxml_use_internal_errors(true);
        $this->preserveWhiteSpace = false;
        $this->strictErrorChecking = false;
    }

    function setSite($site){
        $this->site = $site;
        return $this;
    }

    function setSource(){
        if(empty($this->site))return 'Error: Missing $this->site, use setSite() first';
        $this->source = $this->get_data($this->site);
        return $this;
    }

    function getInnerHTML($tag, $id=null, $nodeValue = false){
        if(empty($this->site))return 'Error: Missing $this->source, use setSource() first';
        $this->loadHTML(mb_convert_encoding($this->source, 'HTML-ENTITIES', 'UTF-8'));

        $tmp = $this->getElementsByTagName($tag);
        $ret = null;
        foreach ($tmp as $v){
            if($id !== null){
                $attr = explode('=',$id);
                if($v->getAttribute($attr[0])==$attr[1]){
                    if($nodeValue == true){
                        $ret .= trim($v->nodeValue);
                    }else{
                        $ret .= $this->innerHTML($v);
                    }
                }
            }else{
                if($nodeValue == true){
                    $ret .= trim($v->nodeValue);
                }else{
                    $ret .= $this->innerHTML($v);
                }
            }
        }
        return $ret;
    }

    function innerHTML($dom){
        $ret = "";
        $nodes = $dom->childNodes;
        foreach($nodes as $v){
            $tmp = new DOMDocument();
            $tmp->appendChild($tmp->importNode($v, true));

            $ret .= trim($tmp->saveHTML());
        }
        return $ret;
    }

    function get_data($url){
        if(function_exists('curl_init')){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
        }else{
            return file_get_contents($url);
        }
    }
}
?>
و برای نمایش در هر جای سایت:


کد:
<?php echo '<table>'.$scraper->getInnerHTML('table','id=tbl_gold-mrkt').'</table>'; ?>
اگر توجه کنی. میگم برو جدولی که شناسه ایدی tbl_gold-mrkt رو بخون و نمایشش بده...

اون بالا هم ادرس سایت رو میدی (خط 5)

 

Pro Mind

تازه وارد
ممنونم محمد جان

من این کد را به صورت تست در لوکال هاست امتحان کردم به این شکل


کد:
<html>
<head>
 <?php 
ini_set('max_execution_time', 300);
$scraper = new DOMScraper();
//address ro inja bede
$scraper->setSite('http://www.cinemakhabar.ir/')->setSource();


Class DOMScraper extends DOMDocument{
    public $site;
    private $source;
    private $dom;

    function __construct(){
        libxml_use_internal_errors(true);
        $this->preserveWhiteSpace = false;
        $this->strictErrorChecking = false;
    }

    function setSite($site){
        $this->site = $site;
        return $this;
    }

    function setSource(){
        if(empty($this->site))return 'Error: Missing $this->site, use setSite() first';
        $this->source = $this->get_data($this->site);
        return $this;
    }

    function getInnerHTML($tag, $id=null, $nodeValue = false){
        if(empty($this->site))return 'Error: Missing $this->source, use setSource() first';
        $this->loadHTML(mb_convert_encoding($this->source, 'HTML-ENTITIES', 'UTF-8'));

        $tmp = $this->getElementsByTagName($tag);
        $ret = null;
        foreach ($tmp as $v){
            if($id !== null){
                $attr = explode('=',$id);
                if($v->getAttribute($attr[0])==$attr[1]){
                    if($nodeValue == true){
                        $ret .= trim($v->nodeValue);
                    }else{
                        $ret .= $this->innerHTML($v);
                    }
                }
            }else{
                if($nodeValue == true){
                    $ret .= trim($v->nodeValue);
                }else{
                    $ret .= $this->innerHTML($v);
                }
            }
        }
        return $ret;
    }

    function innerHTML($dom){
        $ret = "";
        $nodes = $dom->childNodes;
        foreach($nodes as $v){
            $tmp = new DOMDocument();
            $tmp->appendChild($tmp->importNode($v, true));

            $ret .= trim($tmp->saveHTML());
        }
        return $ret;
    }

    function get_data($url){
        if(function_exists('curl_init')){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
        }else{
            return file_get_contents($url);
        }
    }
}
?> 

</head>
<body>
 <?php echo '<div>'.$scraper->getInnerHTML('div','id=tabPages1').'</div>'; ?> 
 </body>
 </html>
ولی هیچ چیزی نمایش نمیده

ممنون میشم جوابمو بدی

 

hannanstd.ir

مدیر انجمن و توسعه دهنده ووکامرس پارسی
از


کد:
<?php echo  file_get_contents('http://www.cinemakhabar.ir/'); ?>
هم میتونی استفاده کنی ... استایل قالب خودت هم روش جواب میده ...

ولی ... اینکه بشه فقط یک بخش خاصی از سایت رو بارگذاری کنی تست نکردم ....

 

Mohammad

مدیر انجمن
پرسنل مدیریت
اخر ادرس سایتش index.php هم بزن...

لوکال تست نکنی بهتره

 

Pro Mind

تازه وارد
به خط 70 گیر میده

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

این ارورشه ولی نشون میده اون قسمت را

Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /public_html/nb-cs/untitled file.php on line 70

اگه بخوام اینو بزارم توی ورد پرس چطوری بزارم ک مشکل ایجاد نکنه

 

Mohammad

مدیر انجمن
پرسنل مدیریت
این خطای امنیتی هست. مربوط به سروره. به مدیر سرور بگید براتون رفع کنه... safe mode روشنه...

 
بالا