예제 #1
0
 /**
  * 
  */
 private function GetSEOState($taskID)
 {
     $dataProvider = new CActiveDataProvider(SiteUrl::model(), array('pagination' => false));
     echo '資料庫共' . $dataProvider->totalItemCount . '筆資料' . "\r\n";
     $i = 0;
     foreach ($dataProvider->getData() as $record) {
         $site = $record->site;
         $id = $record->SiteID;
         // if($i>=5)
         // {
         // 	break;
         // }
         //移除前面的http:// (若有的話)
         $site = preg_replace('#^https?://#', '', $site);
         $site = preg_replace('#^http?://#', '', $site);
         //系統延遲
         $pagerank = 0;
         $now = new DateTime();
         try {
             $pagerank = \SEOstats\Services\Google::getPageRank($site);
             if (!is_numeric($pagerank)) {
                 $pagerank = null;
             }
         } catch (Exception $e) {
             $pagerank = null;
         }
         usleep(rand(1000, 3000));
         //下面這行是採用Google API提供之資料
         //$googleIds = \SEOstats\Services\Google::getSiteindexTotal($site);
         //下面這行是採用網頁搜尋結果資料
         if ($i % 2 == 1) {
             usleep(rand(500, 1000));
             $googleIds = $this->GetGoogleSearch("site:{$site}");
         } else {
             $googleIds = $this->GetGoogleSearch("site:{$site}");
         }
         sleep(3);
         if (is_null($googleIds)) {
             //用另外種管道重抓一次
             usleep(rand(5000, 10000));
             echo '[log]' . $site . "使用重抓索引資料;/r/n";
             $googleIds = \SEOstats\Services\Google::getSiteindexTotal($site);
         }
         if ($i % 2 == 1) {
             usleep(rand(500, 1000));
             $googleLinks = $this->GetGoogleSearch("link:{$site}");
         } else {
             $googleLinks = $this->GetGoogleSearch("link:{$site}");
         }
         //如果抓不到資料就換個管道
         if (is_null($googleLinks)) {
             //用另外種管道重抓一次
             usleep(rand(5000, 10000));
             echo '[log]' . $site . "使用API重抓頁面數資料;/r/n";
             $googleLinks = \SEOstats\Services\Google::getBacklinksTotal($site);
         }
         usleep(rand(1010, 15020));
         //echo("[log]".$now->format( 'Y-m-d H:i:s' )."搜尋".$site."有".$googleLinks.'項結果 '."\r\n");
         //取得社群分享數據
         $seostats = new \SEOstats\SEOstats();
         $seostats->setUrl("http://{$site}");
         $fb = Social::getFacebookShares();
         //print_r($fb);
         usleep(rand(4000, 10000));
         //
         //設定抓取的檔案類型
         //
         $fileTypeList = array('pdf', 'doc', 'docx', 'ppt', 'pptx', 'ps', 'eps');
         $fileCount = array();
         $error_statues = 0;
         foreach ($fileTypeList as $key => $value) {
             usleep(rand(5000, 10000));
             if ($error_statues == 0) {
                 $fileCount[$value] = $this->GetGoogleSearch("site:{$site}" . ' filetype:' . $value);
             }
             if (is_null($fileCount[$value])) {
                 $fileCount[$value] = \SEOstats\Services\Google::getSiteFileTypeTotal($site, $value);
                 //表示系統被Google封鎖了。
                 if (is_null($fileCount[$value])) {
                     $fileCount[$value] = 0;
                     $error_statues++;
                 }
             }
         }
         usleep(rand(4000, 10000));
         //取得網站資訊,包含網站一些設定資訊。
         $info = $this->get_url_info($site);
         $model = new Data();
         $model->attributes = array('SiteID' => $id, 'GoogleData' => $googleIds, 'google_backlink' => $googleLinks, 'filetime' => $info['filetime'] = !-1 ? date("Y-m-d H:i:s", $info['filetime']) : null, 'robot' => $this->remoteFileExists("{$site}/robots.txt"), 'sitemap' => $this->remoteFileExists("{$site}/sitemap.xml"), 'Time' => $now->format('Y-m-d H:i:s'), 'Facebook' => $fb['total_count'], 'FB_share_count' => $fb['share_count'], 'FB_like_count' => $fb['like_count'], 'FB_comment_count' => $fb['comment_count'], 'FB_commentsbox_count' => $fb['commentsbox_count'], 'FB_click_count' => $fb['click_count'], 'TwitterShares' => Social::getTwitterShares(), 'LinkedInShares' => Social::getLinkedInShares(), 'pdf' => $fileCount['pdf'], 'doc' => $fileCount['doc'], 'docx' => $fileCount['docx'], 'ppt' => $fileCount['ppt'], 'pptx' => $fileCount['pptx'], 'ps' => $fileCount['ps'], 'eps' => $fileCount['eps'], 'YY' => $now->format('Y'), 'MM' => $now->format('m'), 'DD' => $now->format('d'), 'TaskID' => $taskID, 'google_page_rank' => $pagerank);
         //Yii::app()->end();
         if ($model->save()) {
             $i++;
         } else {
             print "網址: {$site} 出現錯誤";
             print_r($model->getErrors());
         }
         usleep(rand(100, 400));
         // if($i==3)
         // {
         // 	break;
         // }
     }
     echo '執行完畢,共儲存' . $i . '筆資料';
 }
예제 #2
0
// you need to follow this steps:
//
// 1. Comment-in line 24 (remove hash char "#") and comment-out line 25 (prepend hash char "#")
// 2. Copy this example file (and the others) from ./example/example.php to ./example.php
//
// For further reference see: https://github.com/eyecatchup/SEOstats/issues/49
// Bootstrap the library / register autoloader
#require_once realpath(__DIR__ . '/SEOstats/bootstrap.php');
require_once realpath(__DIR__ . '/vendor/autoload.php');
use SEOstats\Services\Social;
try {
    $url = 'http://www.google.com/';
    // Create a new SEOstats instance.
    $seostats = new \SEOstats\SEOstats();
    // Bind the URL to the current SEOstats instance.
    if ($seostats->setUrl($url)) {
        echo "Social network metrics for " . $url . PHP_EOL;
        /**
         *  Get the total count of +1s for $url on Google+.
         */
        echo "Google+ Shares:          " . Social::getGooglePlusShares() . PHP_EOL;
        /**
         *  Get the total count of mentions of $url on Twitter.
         */
        echo "Twitter Shares:          " . Social::getTwitterShares() . PHP_EOL;
        /**
         *  Get interaction counts (shares, likes, comments, clicks) for $url on Facebook.
         */
        echo "Facebook Shares:         ";
        print_r(Social::getFacebookShares());
        /**
예제 #3
0
 function seo_stat($type = '')
 {
     try {
         $url = base_url();
         $seostats = new \SEOstats\SEOstats();
         if ($seostats->setUrl($url)) {
             if ($type == 'facebook') {
                 return SEOstats\Services\Social::getFacebookShares();
             } elseif ($type == 'gplus') {
                 return SEOstats\Services\Social::getGooglePlusShares();
             } elseif ($type == 'twitter') {
                 return SEOstats\Services\Social::getTwitterShares();
             } elseif ($type == 'linkedin') {
                 return SEOstats\Services\Social::getLinkedInShares();
             } elseif ($type == 'pinterest') {
                 return SEOstats\Services\Social::getPinterestShares();
             } elseif ($type == 'alexa_global') {
                 return SEOstats\Services\Alexa::getGlobalRank();
             } elseif ($type == 'alexa_country') {
                 return SEOstats\Services\Alexa::getCountryRank();
             } elseif ($type == 'alexa_bounce') {
                 return SEOstats\Services\Alexa::getTrafficGraph(5);
             } elseif ($type == 'alexa_time') {
                 return SEOstats\Services\Alexa::getTrafficGraph(4);
             } elseif ($type == 'alexa_traffic') {
                 return SEOstats\Services\Alexa::getTrafficGraph(1);
             } elseif ($type == 'alexa_pageviews') {
                 return SEOstats\Services\Alexa::getTrafficGraph(2);
             } elseif ($type == 'google_siteindex') {
                 return SEOstats\Services\Google::getSiteindexTotal();
             } elseif ($type == 'google_back') {
                 return SEOstats\Services\Google::getBacklinksTotal();
             } elseif ($type == 'search_graph_1') {
                 return SEOstats\Services\SemRush::getDomainGraph(1);
             } elseif ($type == 'search_graph_2') {
                 return SEOstats\Services\SemRush::getDomainGraph(2);
             }
         }
     } catch (\Exception $e) {
         echo 'Caught SEOstatsException: ' . $e->getMessage();
     }
 }