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)); ?>

ただし、サーバーの名前と説明のみが表示されます。これを希望どおりに機能させるにはどうすればよいですか、それとも本当に違うものを使用する必要がありますか。(はいの場合、何を使用するか、例があれば素晴らしいでしょう。)

4

2 に答える 2

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();
于 2012-04-07T12:15:00.667 に答える
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 から各要素を取り出すことで、レイアウトを自分で修正できます。

于 2012-04-07T12:27:51.933 に答える