通过“简单HTML DOM”获得两个跨距之间的文本 [英] Getting the text between two spans with "Simple HTML DOM"

查看:80
本文介绍了通过“简单HTML DOM”获得两个跨距之间的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我需要在两个跨标签之间获取文本,我已经尝试了一堆不同的方法,没有解决方案。
我也使用简单的HTML DOM Parser(http://simplehtmldom.sourceforge.net/),所以我可以做的只是一点限制。
这是基本设置:

Basically, I need to get the text between two span tags, and I've tried a bunch of different methods with no solution. I'm using Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net/) too, so what I can do is a little restricted to. Here is the basic setup:

<span class=1>text here</span> TEXT I NEED TO GET <span class=2>more text</span>

任何帮助?

推荐答案

span元素之间的文本应该是一个DOMTextNode,并且与span元素相似。如果SimpleHTMLDom遵循 DOM规范,您应该能够得到它:

The text between the span elements should be a DOMTextNode and sibling to the span elements. If SimpleHTMLDom follows DOM specs you should be able to get it with:

$text = $html->find('span[class=1]', 0)->next_sibling();

如果这不起作用,请考虑使用基于libxml的更合适的解析器,例如见

If that doesnt work, consider using a more proper parser that is based on libxml, e.g. see

  • How do you parse and process HTML/XML in PHP?

这篇关于通过“简单HTML DOM”获得两个跨距之间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆