php - 简单的HTML DOM-(直接)子选择器

标签 php css-selectors simple-html-dom

如何获得带有文字标题的a元素的内部文字?

我正在尝试使用$html->find('#someid p > a'),但它包含所有嵌套的后代a元素。

<div id="someid">
    <tr>... Same structure ...<tr>
    <tr>
        <td>
            <p>
                <a href="#">Title</a>
                <br>
                <span class="someClass">
                    <a href="#">text1</a>
                    <a href="#">text2</a>
                    <a href="#">text3</a>
                    <a href="#">text4</a>
                </span>
            </p>
            <p>text5</p>
        </td>
        <td>text6</td>
    </tr>
    <tr>...<tr>
</div>

最佳答案

尝试:

$ e = $ html-> find(''#someid p> a',0);
//或输入first_child

关于php - 简单的HTML DOM-(直接)子选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8375361/

相关文章:

php - 如何在 MySQL 中搜索 'near word'?

php - 简单的 PHP/cURL 缓存

css - 悬停不与第 n 个 child 一起工作

css - nth-of-type 与 nth-child

php - 如何在 PHP 中获取 DIV 的 HTML 内容

java - 在 PHP 中寻找像简单 html dom 一样的 java html 解析器

php - ajax中的功能不起作用

CSS 3 nth of type 仅限于类

php - 如何使用简单的 HTML Dom 从 For 循环将数据作为单个查询插入 MYSQL 数据库

php - 用户设计模式