简体   繁体   English

如何使用simplehtmldom选择没有元素的内容

[英]How to select content without element using simplehtmldom

I am trying to extract data from a website using PHP with the help of simplehtmldom. 我正在尝试在simplehtmldom的帮助下使用PHP从网站中提取数据。

The problem is that there is a text which doesn't have any parent element. 问题在于,有一个文本没有任何父元素。

<div class="div_1">First div</div> The text i need to grab <div class="div_2">Second div</div>

In the above demonstration i need to extract The text i need to grab . 在上面的演示中,我需要提取The text i need to grab

If simplehtmldom is not required, try Regular Expressions: 如果不需要simplehtmldom,请尝试使用正则表达式:

<div[^<>]*class="div_1"[^<>]*>.*?</div>(.*?)<div[^<>]*class="div_2"[^<>]*>.*?</div>

http://regexr.com/3bd5f http://regexr.com/3bd5f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM