我有輕微的不同structure.i頁面索引正在通過許多網頁試圖循環,做到以下幾點: -檢查不同的節點和相應的呼應
1.如果td[2]
具有跨類THN呼應類。 2.if td[2]
具有img節點,然後對src
爲http://example.com/img/star01.giff
的節點數進行計數並回顯總數。
我能夠做第一部分,但不是第二部分。
pagetype1
<tbody>
<tr>
<td>Name1</td>
<td>
<span class="star5-05">
</td>
</tr>
<tr>
<td>Name2</td>
<td>
<span class="star5-05">
</td>
</tr>
</tbody>
pagetype2
<tbody>
<tr>
<td>Name1</td>
<td>
<img alt="" src="http://example.com/img/star01.gif">
<img alt="" src="http://example.com/img/star01.gif">
<img alt="" src="http://example.com/img/star01.gif">
<img alt="" src="http://example.com/img/star01.gif">
<img alt="" src="http://example.com/img/star02.gif">
</td>
</tr>
<tr>
<td>Name2</td>
<td>
<img alt="" src="http://example.comimg/star01.gif">
<img alt="" src="http://example.comimg/star01.gif">
<img alt="" src="http://example.comimg/star01.gif">
<img alt="" src="http://example.comimg/star01.gif">
<img alt="" src="http://example.com/img/star02.gif">
</td>
</tr>
</tbody>
我的代碼
foreach($my_nodes as $my_node)
{
$tmp=$my_xpath->query('td[1]',$my_node);
if ($tmp->length>0)
{
$tmp=$tmp->item(0)->textContent;
if ($tmp=="Name1")
{
$chkstars=$my_xpath->query('td[2]/span/@class',$my_node);
if ($chkstars->length>0)
{
$tmp_stars=$chkstars->item(0)->textContent;
}
else
{
$tmp_stars=$my_xpath->evaluate('count(//td[2]/img[@src="http://www.example.com/img/star01.gif"]),$my_node)');
}
echo $tmp_stars."<br>";
}
}
}
'$ my_xpath->評估('計數(// IMG [@ SRC =「HTTP:/ /example.comimg/star01.gif「]));' – splash58
在哪裏我應該把這個計數(// img [@ src =」http://example.comimg/star01.gif「]) –
或者如果你想只計算該行的img - '$ my_xpath-> evaluate('count(.mimg [@ src =「http://example.comimg/star01.gif」]),$ my_node);' – splash58