假设我有一个 HTML 页面如下:
<!-- This is the opening tag -->
<div class="content_text">
<div>Title</div>
<div>Author Name</div>
<div>Some complicated HTML elements correctly validated</div>
<b>Some more text</b>
<img ... />
<div> more and more text </div>
</div><!-- This is the correct closing tag -->
如何获取带有 class="content_text"
的 div 开头与其正确的结束标记之间的内容?
我尝试了正则表达式,但找不到任何简单甚至困难的方法。
我试过了 XPath , 但我仍然无法获取内容。相反,我在外部 div 中获取了文本。
最佳答案
您可以使用 PHP Simple HTML DOM Parser像 DOMDocument
解析 XML 一样解析 HTML。
关于PHP:如何获取 HTML 元素的正确结束标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15913457/