我有轻微的不同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