2012-04-07 74 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