English 中文(简体)
DOM xppath html提取
原标题:DOM xpath html extraction
  • 时间:2012-05-26 19:46:51
  •  标签:
  • dom
  • xpath

我正在将一些 html 导入到 DOM 文件 AS 使用 xpath 提取我感兴趣的 html 部分 。 见 :

$dom = new DOMDocument();
@$dom->loadHTML( $myHtmlFileHere );
$xpath_dom_doc = new DomXPath($dom);
$dom_object = $dom_document->query( myPathHere );

以下的 html 结构“ 已返回 ” :

<div>GROUP A</div>
<span>aaa</span>
<span>zzz awesome</span>
<span>eee</span>

<div>GROUP B</div>
<span>fff</span>

<div>GROUP C</div>
<span>zzz</span>
<span>uuu</span>
<span>iii</span>
<span>rrr</span>

正如你们所见,我有类别(GROUP A、B组和C组)。在每一类别下方,我都有与该类别有关的信息。我要的是将相关类别内容的宽度发送到一个 db 上。我面临的问题是,该类别的div 标记没有覆盖宽度。所以我不明白如何管理。希望有人能帮助。先谢谢你。干杯。

最佳回答

following-sibling xpath 函数如何? 您应该小心, 并且只选择兄弟姊妹到下一个 div

例如,用xsh2:

$div = //div[2] ;
ls $div/following-sibling::span[count(preceding-sibling::div)=1+count($div/preceding-sibling::div)] ;
问题回答

暂无回答




相关问题
PHP DOM - accessing newly added nodes

I use the following to get a html document into DOM: $dom = new domDocument( 1.0 , utf-8 ); $dom->loadHTML($html) and then I add some new content to an element in the html: $element = $dom->...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

How to get a flash url in a webpage using a webframe?

As we know , When we load frame from webpage of safari, we will invoke the delegate methods of webkit informal protocol(WebFrameLoadDelegate): webView:didStartProvisionalLoadForFrame: webView:...

热门标签