我正在使用以下 xpath 来获取如下图所示的部分(http://advrider.com/forums/),但不是。有什么问题吗?
//TABLE/TBODY/TR[@class='dg-forums-level2 dg-align-center']/TD[2]/DIV[1]/A[1]
更新
<?php
$BASE_PATH = "../src/";
include_once($BASE_PATH . "classes/forumdb.php");
include_once($BASE_PATH . "classes/curl.php");
$curl = new curl();
$html = $curl->get_web_page('http://advrider.com/forums/');
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
//$elements = $xpath->query("//TABLE[@class='tborder']/TBODY/TR[@class='']/TD[2]/DIV[1]/A[1]/STRONG[1]");
$elements = $xpath->query("//*[@id='f3']"); //works
//$elements = $xpath->query("//TABLE/TBODY/TR");
//TD[@id='f74']/DIV[1]/A[1]
if (!is_null($elements))
{
foreach ($elements as $element)
{
echo "f<br/>[". $element->nodeName. "]";
$nodes = $element->childNodes;
foreach ($nodes as $node)
{
echo $node->nodeValue. "\n";
}
}
}
?>