PHP Simple HTML DOM Parser

后端 未结 2 1164
失恋的感觉
失恋的感觉 2021-01-15 08:04

I just started to use PHP Simple HTML DOM Parser.

Now I\'m trying to extract all elements surrounded with a -tag inclduing

2条回答
  •  终归单人心
    2021-01-15 08:33

    Try the following CSS selector

    b > span.marked
    

    That would return the span though, so you probably have to do $e->parent() to get to the b element.

    Also see Best Methods to parse HTML for alternatives to SimpleHtmlDom


    Edit after update:

    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'
    

    Also, your question does not match the queries. You asked how to find

    elements surrounded with the ,-tags followed by a

    That can be read to either mean

    foo
    

    or

    foofoo
    

    For that first use the child combinator I have shown earlier. For the second, use the adjacent sibling combinator

    b + span.marked
    

    to get the span and then use $e->prev_sibling() to return the previous sibling of element (or null if not found).

    However, in your shown markup, there is neither nor. There is only a DIV with a SPAN child having the marked class

    marked

    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.

提交回复
热议问题