更新时间:2022-04-09 23:15:48
尝试以下 CSS选择器
b > span.marked
这将返回跨度,所以你可能要做 $ e-> parent()
以获取b元素。
That would return the span though, so you probably have to do $e->parent()
to get to the b element.
另请参阅解析HTML的***方法 for SimpleHtmlDom的替代方法
Also see Best Methods to parse HTML for alternatives to SimpleHtmlDom
更新后修改:
您的浏览器将修改DOM 。 如果您查看标记,您将看到没有tbody元素。但是Firebug给你
Your browser will modify the DOM. If you look at your markup, you will see that there is no tbody elements. Yet Firebug gives you
html body div#wrapper table.desc tbody tr td div span.marked'
html body div#wrapper table.desc tbody tr td table.split tbody tr td b'
另外,你的问题不符合查询。你问如何找到< b>,< / b> $包围的
Also, your question does not match the queries. You asked how to find
c $ c> -tags后跟一个
< span class =marked>
可以读取,意思是
<b><span class="marked">foo</span></b>
或
<b><element>foo</element></b><span class="marked">foo</span>
For that first use the child combinator I have shown earlier. For the second, use the adjacent sibling combinator
b + span.marked
获取跨度,然后使用 $ e-> prev_sibling()
返回元素的上一个同级元素(如果未找到则为null)。
to get the span and then use $e->prev_sibling()
to return the previous sibling of element (or null if not found).
但是,在您显示的标记中,既没有也没有。只有DIV与SPAN孩子有标记的类
However, in your shown markup, there is neither nor. There is only a DIV with a SPAN child having the marked class
<div style="text-align: center"> <span class="marked">marked</span>
如果这是你想要匹配的,那就是子组合器。当然,你必须将b改为div。
If that is what you want to match, it's the child combinator again. Of course, you have to change the b then to a div.