简单的HTML DOM解析器得到文本没有标签
问题描述:
我想解析一个HTML对象使用简单的HTML DOM解析器使用PHP。我想提取的特定部分没有正确包装在任何标签中。简单的HTML DOM解析器得到文本没有标签
<li class="tags">
Required text: <span itemprop="testCat"><a href="/topics/new-topic/index.html" title="New Topic" onclick="s_objectID="http://www.example.com/topics/new-topic/index.html_1";return this.s_oc?this.s_oc(e):true">New Topic</a></span>, <span itemprop="testCat"><a href="/topics/new-topic-2/index.html" title="New Topic" onclick="s_objectID="http://www.example.com/topics/new-topic-2/index.html_1";return this.s_oc?this.s_oc(e):true">New Topic</a></span>, <span itemprop="testCat"><a href="/topics/new-topic-3/index.html" title="New Topic 3" onclick="s_objectID="http://www.example.com/topics/new-topic-3/index.html_1";return this.s_oc?this.s_oc(e):true">New Topic 3</a></span>,
<div class="more">
<a href="javascript: void(0);" class="more-trigger" onclick="s_objectID="javascript: void(0);_1";return this.s_oc?this.s_oc(e):true">more</a>
<div class="more-tags" style="top: 15px; left: 0px; display: none;">
<div class="hd"></div>
<div class="bd">
<ul id="topic-filedin">
<li>Another Required Text :
<a href="/topics/new-topic-4/index.html" onclick="s_objectID="http://www.example.com/topics/new-topic-4/index.html_1";return this.s_oc?this.s_oc(e):true">New Topic 4</a>
</li>
<li>Topic Intended For :
<a href="/topics/for-kids/index.html" onclick="s_objectID="http://www.example.com/topics/for-kids/index.html_1";return this.s_oc?this.s_oc(e):true">For Kids</a>
</li>
</ul>
</div>
<div class="ft"></div>
</div>
<script type="text/javascript">
SNI.Node.ArticleInfo.moreTags();
</script>
</div>
</li>
我能够得到使用
$categories = $single_content->find('li[class=tags] span');
foreach ($categories as $key) {
echo $key->plaintext . '<br>';
}
包裹标签中的文本,我无法找出Required text
和Another Required Text
和Topic Intended For
。
答
要获得 '另一个所需的文本' 和 '主题旨在' 您可以使用此 -
$文字= $ single_content->找到( “UI [CLASS =话题filedin] /李”);
$ textArray = array();
的foreach($文本$ TA)
{
$textArray[] = $ta->plaintext;
}
,你会得到一个数组所需要的文字。