到目前为止,我的代码使用xPath查询获取所有类的'forumRow'。我如何获得每个'forumRow'类中存在的a元素的href属性?PHP DomXPath - 按类别获取子项
我有点卡住了,我可以从第一个查询的结果开始运行查询。
我当前的代码
$this -> boards = array();
$html = @file_get_contents('http://www.roblox.com/Forum/Default.aspx');
libxml_use_internal_errors(true);
$page = new DOMDocument();
$page -> preserveWhiteSpace = false;
$page -> loadHTML($html);
$xpath = new DomXPath($page);
$board_array = $xpath -> query('//*[@class="forumRow"]');
foreach($board_array as $board)
{
$childNodes = $board -> childNodes;
$boardName = $childNodes -> item(0) -> nodeValue;
if (strlen($boardName) > 0)
{
$boardDesc = $childNodes -> item(1) -> nodeValue;
array_push($this -> boards, array($boardName, $boardDesc));
}
}
$Cache -> saveData(json_encode($this -> boards));