为什么这会返回整个 html 文档,而不仅仅是来自包含“H+R+E”的节点的值?
html示例:
<tr class="linesAlt1">
<td>04:10 PM</td><td style="width:53%;">3055 Over</td><td style="width:22%;">3 H+R+E +146</td>
</tr>
我想得到"3 H+R+E +146"
。但这会转储所有 html。
<?php
$url = 'http://www.pinnaclesports.com/ContestCategory/MLB+Propositions/July+13~2C~+2012/Lines.aspx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
foreach ($xpath->query("//table/tr/td[contains(., 'H+R+E')]") as $textNode){
echo $textNode->nodeValue."\n";
}
?>