2017-02-14 13 views
0

私は単純なHTML Domを使用してHTMLテーブルを削っています。 私はその指示に従い、他の多くのコード例を見てきましたが、file_get_htmlはうまくいかないようです。file_get_htmlエラー、動作していません

<?php 

// Simple HTML Dom Parser 
include('simple_html_dom.php'); 

//$worlds = ["Amera", "Antica", "Astera", "Aurera", "Aurora", "Bellona", "Belobra", "Beneva", "Calmera", "Calva", "Calvera", "Candia", "Celesta", "Chrona", "Danera", "Dolera", "Efidia", "Eldera", "Ferobra", "Fidera", "Fortera", "Garnera", "Guardia", "Harmonia", "Honera", "Hydera", "Inferna", "Iona", "Irmada", "Julera", "Justera", "Kenora", "Kronera", "Laudera", "Luminera", "Magera", "Menera", "Morta", "Mortera", "Neptera", "Nerana", "Nika", "Olympa", "Osera", "Pacera", "Premia", "Pythera", "Quilia", "Refugia", "Rowana", "Secura", "Serdebra", "Shivera", "Silvera", "Solera", "Tavara", "Thera", "Umera", "Unitera", "Veludera", "Verlana", "Xantera", "Xylana", "Yanara", "Zanera", "Zeluna"]; 

//foreach ($worlds as $world) { 
    // All HTML from the online list 
    $html = file_get_html('https://secure.tibia.com/community/?subtopic=worlds&world=Antica'); 

    // Search for the online list table content 
    foreach ($html->find('tr[class=Table2]') as $row) { 
    $name = $row->find('td', 0)->plaintext; 
    $level = $row->find('td', 1)->plaintext; 
    $vocation = $row->find('td', 2)->plaintext; 

    echo $name . ' | ' . $level . ' | ' . $vocation . '<br>'; 
    } 
//} 

?> 

そして私はこれらのエラーを取得:ここ

は私のコードです

Warning: file_get_contents(): stream does not support seeking in D:\xampp\htdocs\simple_html_dom.php on line 76 

Warning: file_get_contents(): Failed to seek to position -1 in the stream in D:\xampp\htdocs\simple_html_dom.php on line 76 

Fatal error: Uncaught Error: Call to a member function find() on boolean in D:\xampp\htdocs\index.php:13 Stack trace: #0 {main} thrown in D:\xampp\htdocs\index.php on line 13 

は私が間違って何をしているのですか? 私はこすりしようとしているテーブルには、上の「プレイヤーオンライン」のテーブルです: https://secure.tibia.com/community/?subtopic=worlds&world=Antica

答えて

2

試しのような、より堅牢なライブラリを使用する必要があるかもしれないと思いますこれは:

$html = str_get_html(file_get_contents($url)); 
+0

これはうまくいきました。今、私はいくつかのHTMLを取得しています。ありがとう! –

3

これはPHPの最新バージョンのsimple_html_domライブラリ問題です。 は単に「$offset = -1,」に変更し、それを修正するには「simple_html_dom.php」ファイルの「file_get_html」関数のパラメータで「$offset = 0,」。

+0

すばらしい、これは答えでなければなりません! –

関連する問題