//-------------------------------------------------------------------------------------------------------------------------------| //-----if you start getting a bunch of 0's or NA's, remember that there are pretty low limits to Alexa and Google calls...-------| //-------------------------------------------------------------------------------------------------------------------------------| $alexa = SEOstats\Alexa::getGlobalRank(); $pagerank = SEOstats\Google::getPageRank(); $g_links = SEOstats\Google::getBacklinksTotal("www." . $row[0]); $g_links_no_www = SEOstats\Google::getBacklinksTotal($row[0]); $g_plus_count = SEOstats\Social::getGooglePlusShares(); $twitter_shares = SEOstats\Social::getTwitterShares(); $linkedin_shares = SEOstats\Social::getLinkedInShares(); echo "<div class='row'><div class='col-md-12'><h3>" . $row[0] . "</h3>"; echo "<div class='row'><div class='col-md-7'>Alexa rank = " . SEOstats\Alexa::getGlobalRank() . "<br />"; echo "Daily traffic graph: " . SEOstats\Alexa::getTrafficGraph(1) . "<br /></div>"; echo "<div class='col-md-3'>PageRank = " . SEOstats\Google::getPageRank() . "<br />"; echo "Google links = " . SEOstats\Google::getBacklinksTotal("www." . $row[0]) . "<br />"; echo "Google links (no www) = " . SEOstats\Google::getBacklinksTotal($row[0]) . "<br />"; echo "Twitter shares: " . SEOstats\Social::getTwitterShares() . "<br />"; echo "Plus ones: " . SEOstats\Social::getGooglePlusShares() . "<br />"; echo "Twitter shares: " . SEOstats\Social::getTwitterShares() . "<br />"; echo "Linkedin shares: " . SEOstats\Social::getLinkedInShares() . "<br /><br /></div>"; echo "<div class='col-md-3'>SEMRush Search Engine Traffic Graph: " . SEOstats\SemRush::getDomainGraph(1) . "<br /></div></div></div></div>"; //----------------------------------------------------------------------------------------| //--------------------uncomment this stuff when you want to insert into MySQL!!-----------| //----------------------------------------------------------------------------------------| /* Prepared statement, stage 1: prepare */ //if (!($stmt = $mysqli->prepare("INSERT INTO seo (url, alexa, pagerank, link_num, linked_pages, g_links, g_links_no_www, g_plus_ones, linkedin_shares) VALUES (?,?,?,?,?,?,?,?)"))) { // echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; //} //if (!$stmt->bind_param("siiiiiiii", $url, $alexa, $pagerank, $link_num, $linked_pages, $g_links, $g_links_no_www, $g_plus_ones, $linkedin_shares)) { // echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; //}
// 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\Google; try { /** * Get an array containing URL and title for the first * 100 results for a Google web search for 'keyword'. */ $serps = Google::getSerps('keyword'); print_r($serps); /** * Get an array containing URL and title for the first * 200 results for a Google web search for 'keyword'. */ //$serps = Google::getSerps('keyword', 200); //print_r($serps); /** * Get an array containing URL, title and position in Serps * for each occurrence of 'http://www.domain.tld' within the * first 1000 results for a Google web search for 'keyword'. */ //$serps = Google::getSerps('keyword', 1000, 'http://www.domain.tld'); //print_r($serps); } catch (\Exception $e) {
/** * SEOstats Example - Get Google PageRank * * @package SEOstats * @author Stephan Schmitz <*****@*****.**> * @copyright Copyright (c) 2010 - present Stephan Schmitz * @license http://eyecatchup.mit-license.org/ MIT License * @updated 2013/12/04 */ // NOTE: The given path to the autoload.php assumes that you installed SEOstats via composer // and copied this example file from ./vendor/seostats/seostats/example/example.php to ./example.php // // If you did NOT installed SEOstats via composer but instead downloaded the zip file from github.com, // 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'); try { $url = testURL; // Get the Google PageRank for the given URL. $pagerank = \SEOstats\Services\Google::getPageRank($url); echo "The current Google PageRank for {$url} is {$pagerank}." . PHP_EOL; } catch (\Exception $e) { echo 'Caught SEOstatsException: ' . $e->getMessage(); }
/** * */ 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 . '筆資料'; }
public function getGoogle() { return intval(\SEOstats\Services\Google::getPageRank($this->url)); }
<div class="panel-body"> <div class="row"> <div class="col-md-6"> <table class="table custom-border"> <tr> <td class="vmiddle width30pers"> <img src="img/google.png" alt="Google Index"> Google Index </td> <td class="vmiddle"> <strong> <?php $seostats = new \SEOstats\SEOstats(); $url = "http://www." . $domain; if ($seostats->setUrl($url)) { print SEOstats\Google::getSiteindexTotal(); } ?> </strong> </td> </tr> <tr> <td class="vmiddle"> <img src="img/yahoo.png" alt="Yahoo Index"> Yahoo Index </td> <td class="vmiddle"> <strong>0</strong> </td> </tr> <tr>
* * @package SEOstats * @author Stephan Schmitz <*****@*****.**> * @copyright Copyright (c) 2010 - present Stephan Schmitz * @license http://eyecatchup.mit-license.org/ MIT License * @updated 2013/12/17 */ // NOTE: The given path to the autoload.php assumes that you installed SEOstats via composer // and copied this example file from ./vendor/seostats/seostats/example/example.php to ./example.php // // If you did NOT installed SEOstats via composer but instead downloaded the zip file from github.com, // 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'); try { $url = 'http://www.nahklick.de/'; /** * Get the Google Pagespeed Analysis metrics for the given URL. * NOTE: Requires an API key to be set in SEOstats/Config/ApiKeys.php */ $pagespeed = \SEOstats\Services\Google::getPagespeedAnalysis($url); print_r($pagespeed); } catch (\Exception $e) { echo 'Caught SEOstatsException: ' . $e->getMessage(); }