[英]SimpleHTMLDOM - Exclude element inside div
I'm using SimpleHTMLDOM and trying to get some content from a site. 我正在使用SimpleHTMLDOM并尝试从网站获取一些内容。 And I must say that im very happy with using SimpleHTMLDOM, but I can't find anything on my problem and how to solve it. 我必须说,我对使用SimpleHTMLDOM感到非常满意,但是我找不到关于我的问题以及如何解决的任何信息。
The goes like this: I'm trying to extract the string from a follow element: foo. 事情是这样的:我正在尝试从跟随元素:foo中提取字符串。
This is the markup for element foo on the site: 这是站点上元素foo的标记:
<div class="foo">
Lorem Ipsum
<div class="bar"></div>
</div>
And the php code i'm using is like this: 我正在使用的php代码是这样的:
foreach($html->find('.foo ') as $m)
$foo = $m->innertext;
This will output: 这将输出:
Lorem Ipsum <div class="bar"></div>
So my question is how to exclude the div/element inside the class foo? 所以我的问题是如何在foo类中排除div / element?
Thanks in advance! 提前致谢!
I think you can find the first text node with something similar to the following... 我认为您可以找到与以下内容类似的第一个文本节点...
foreach($html->find('.foo') as $foo)
echo $foo->find('text', 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.