我想写使用simplehtmldom网络刮刀。我想通过搜索标签的内容,以获得一个标签。这是它里面的明文,没有标签的类型。然后,一旦我通过搜索其纯文本的内容具有标签我想以后得到一个标签。

如何找到基于其内容的标签?一旦我有我怎么发现下面的标签?

任何帮助,将不胜感激。

感谢。

有帮助吗?

解决方案

下面将让您搜索所有文本节点,然后得到一个标签:

// Use Simple_HTML_DOM special selector 'text'
// to retrieve all text nodes from the document
$textNodes = $html->find('text');
$foundTag = null;

foreach($textNodes as $textNode) {
    if($textNode->plaintext == 'Hello World') {
        // Get the parent of the text node
        // (A text node is always a child of
        //  its container)
        $foundTag = $textNode->parent();
        break;
    }
}

if($foundTag) {
    $nextTagAfter = $foundTag->next_sibling();
}

这是不是你的介绍基本的 Simple_HTML_DOM 使用的第一个问题。你可能想阅读官方文档

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top