2012-04-07 91 views
0

左右的值作爲標題說我想要得到這個網站的價值:Xtremetop100 Conquer-Online獲取網站

我的服務器被稱爲Zath-Co和現在我們是在排名11 我要的是腳本會告訴我我們是哪一個級別,我們有多少進出。唯一的問題是我們在列表中上下移動,所以我想要一個腳本來檢查這個名字而不是排名,但是我無法從中找到它。 我想這個腳本

<?php $lines = file('http://xtremetop100.com/conquer-online'); 
    while ($line = array_shift($lines)) { 
    if (strpos($line, 'Zath-Co') !== false) break; } 
    print_r(explode(" ", $line)); ?> 

但它只是顯示我的服務器和描述的名稱。 我該如何獲得這個工作,因爲我想或者我必須使用真正不同的東西。 (如果是,那麼使用什麼,一個例子會很棒。)

回答

0

它也可以使用file()函數修復,就像您自己嘗試一樣。您只需查看源代碼並找到您的「部分」的起始行。我發現(在源代碼中),你需要7行來獲得排名,描述和輸入/輸出數據。這裏是一個測試的例子:

<?php 

$lines = file('http://xtremetop100.com/conquer-online'); 
$CountLines = sizeof($lines); 
$arrHtml = array(); 
for($i = 0; $i < $CountLines; $i++) { 
    if(strpos($lines[$i], '/sitedetails-1132314895')) { 
     //The seven lines taken here under is your section at the site 
     $arrHtml[] = $lines[$i++]; 
     $arrHtml[] = $lines[$i++]; 
     $arrHtml[] = $lines[$i++]; 
     $arrHtml[] = $lines[$i++]; 
     $arrHtml[] = $lines[$i++]; 
     $arrHtml[] = $lines[$i++]; 
     $arrHtml[] = $lines[$i++]; 
     break; 
    } 
} 

//We simply strip all tags, so you just got the content. 
$arrHtml = array_map("strip_tags", $arrHtml); 

//Here we echo the data 
echo implode('<br>',$arrHtml); 

?> 

您可以通過取出從$ arrHtml每個元素通過量環修復自己的佈局。

+0

感謝您的幫助。這正是我想要的。我可以在哪裏與你聯繫? – Arthur1472 2012-04-07 13:08:25

+0

沒問題,我很高興你可以用它來達到你的目的。您可以通過郵件與我聯繫以獲取更多問題 - [email protected] – hskrijelj 2012-04-07 19:16:34

0

我建議使用SimpleXML和XPath。這裏是工作示例:

$html = file_get_contents('http://xtremetop100.com/conquer-online'); 

// suppress invalid markup warnings 
libxml_use_internal_errors(true); 

// Create SimpleXML object 
$doc = new DOMDocument(); 
$doc->strictErrorChecking = false; 
$doc->loadHTML($html); 
$xml = simplexml_import_dom($doc); 

$xpath = '//span[@class="hd1" and ./a[contains(., "Zath-Co")]]/ancestor::tr/td[@class="number" or @class="stats1" or @class="stats"]'; 
$anchor = $xml->xpath($xpath); 

// Clear invalid markup error buffer 
libxml_clear_errors(); 

$rank = (string)$anchor[0]->b; 
$in = (string)$anchor[1]->span; 
$out = (string)$anchor[2]->span; 

// Clear invalid markup error buffer 
libxml_clear_errors(); 
+0

感謝您的幫助。 但我怎樣才能讓它顯示進出的呢? – Arthur1472 2012-04-07 12:21:54

+0

查看更新的答案。 – dfsq 2012-04-07 13:09:38