0
我就開始玩簡單的HTML末日解析器和我有一些麻煩:PHP簡單的HTML DOM解析器 - 環
的HTML代碼如下:
<div class="players">
<ul class="dane">
<li>
<div class="name">Messi</div>
<div class="value">Barcelona</div>
</li>
<li>
<div class="name">Ronaldo</div>
<div class="value">Madryt</div>
</li>
</ul>
</div>
<div class="clubs">
<ul class="dane">
<li>
<div class="name">Barcelona</div>
<div class="value">Hiszpania</div>
</li>
<li>
<div class="name">Madryt</div>
<div class="value">Hiszpania</div>
</li>
</ul>
</div>
<div class="trenerzy">
<ul class="dane">
<li>
<div class="name">Ernesto Valverde</div>
<div class="value">Barcelona</div>
</li>
<li>
<div class="name">Madryt</div>
<div class="value">Zidane</div>
</li>
</ul>
</div>
我的PHP代碼:
include_once('simple_html_dom.php');
$html = file_get_html('http://');
$articles = array();
foreach($html->find('ul.dane') as $article) {
$item['name'] = $article->find('div.name',0)->plaintext;
$item['value'] = $article->find('div.value',0)->plaintext;
$articles[] = $item;
}
print_r($articles);
它接收的數據是:
Array
(
[0] => Array
(
[name] => Messi
[value] => Barcelona
)
[1] => Array
(
[name] => Barcelona
[value] => Hiszpania
)
[2] => Array
(
[name] => Ernesto Valverde
[value] => Barcelona
)
它從數據類ul.dane接收數據,但只有一條記錄,我該如何才能獲取頁面上的所有內容?
我知道我錯過了一個循環的地方,但我有一個問題,找到wher