- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
到目前为止,我的代码正在使用 xPath 查询获取所有类“forumRow”。如何获得在每个“forumRow”类中存在一次的 a 元素的 href 属性?
我有点卡在我可以从第一个查询的结果开始运行查询的地步。
我当前的代码
$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));
最佳答案
遗憾的是,我无法让您的代码正常工作(关于 forumRow <td>
的摘录) - 所以我编造了这个:
$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);
foreach($xpath->query('//td[@class="forumRow"]') as $element){
$links=$element->getElementsByTagName('a');
foreach($links as $a) {
echo $a->getAttribute('href').'<br>';
}
}
/Forum/Search/default.aspx
/Forum/ShowForum.aspx?ForumID=46
/Forum/ShowForum.aspx?ForumID=14
/Forum/ShowForum.aspx?ForumID=44
/Forum/ShowForum.aspx?ForumID=43
/Forum/ShowForum.aspx?ForumID=45
/Forum/ShowForum.aspx?ForumID=21
/Forum/ShowForum.aspx?ForumID=13
...
a very long list
<td class="forumRow">..<a href= ... ></a>..</td>
的所有href
关于PHP DomXPath - 按类获取子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19184903/
如何在不再次查询整个文档的情况下查询子元素的 xpath 结果? 我查询我的文档以找到最后一个 同类menu-item : $doc = new DomDocument(); @$doc->loadH
正在尝试确定哪个更适合我的用例... 对比了这些方法的文档,我模糊的理解是evaluate返回类型化结果但 query没有。此外,query示例包括遍历许多结果,但 evaluate示例假定单一类型的
我面临一个我无法解决的问题。我正在使用 DOMXPath检索 MsgId 的值以下 XML 文件的标记: Test/20171013/CCT10
我这里有一些例子: Mortal Combat: A very good gamenbsp; Call of Duty: Don't buy this game. Street Fighte
到目前为止,我的代码正在使用 xPath 查询获取所有类“forumRow”。如何获得在每个“forumRow”类中存在一次的 a 元素的 href 属性? 我有点卡在我可以从第一个查询的结果开始运行
XML 文件: Root element 4 1 5 3 6
我有这段代码并使用 DOMXPath 删除给定的 td $html = file_get_contents('WebProxy.html'); $xml = new DOMDocument(); $x
我正在使用 DOMDocument/DOMXPath 尝试使 CSS 内联。它会完美地工作,除非我传递给它的 HTML 使它出错,说它不是有效的 XML。 如何设置这些函数来忽略未知标签? 无论如何,
我昨天问了这个问题,当时这正是我所需要的,但是在处理一些实时数据时我发现它并没有完全按照我的预期进行。 Parse HTML with PHP's HTML DOMDocument 它从 HTML 页
假设我有这个: CCC sometexthere AAA sometext DDD something 现在,我想获取 baz 值,它紧跟在
当我想用 XPath 打印计算表达式的结果时出现错误。 $url = $xpath->evaluate('//a/@href', $event);回显 $url ; 我有这个错误:可捕获的 fatal
我有这个 HTML 代码: Hello World 我这样做:$res = $xpath->query(//div[@class='lvlone']/div[@
我有以下html表格结构
我有以下结构: ... ... 问题:基于“输入”标签的“名称”属性选择该tr的表达式是什么?更具体地说,我想知道是否有一种方法,而不必选择输入,然后执行-> parentNode->
当前结构看起来像 //more html //more html //more html //more html
我一直在尝试编写一个 PHP 脚本来使用 DOMXPath 解析 XML 文档。 ;然而我似乎遗漏了一些东西,因为我的 XPath 查询都没有返回任何内容。因此,我尝试淡化我的脚本来尝试解析一个非常基
鉴于此示例文档片段: 300
我使用 DOMXPATH 从 p 标记中删除所有 属性,并且工作正常, // Loop all p. foreach( $dom->getElementsByTagName( "p" ) as $p
我有一段 HTML 代码: Submit 如何在 PHP 中使用 DOMXPath 提取隐藏输入的值?我试过这样的事情: //$site - the html code $doc = n
伙计们,我正在解析 URL 以获取 HTML dom 元素。 这是我的代码: loadHTMLFile($url); $xp = new DOMXPath($dom); $qry = '//scrip
我是一名优秀的程序员,十分优秀!