XPath to select between two HTML comments is not working?

前端 未结 1 1485
轻奢々
轻奢々 2021-01-28 17:17

I\'m trying to select some content between two HTML comments, but having some trouble getting it right (as seen in \"XPath to select between two HTML comments?\"). There seems t

1条回答
  •  滥情空心
    2021-01-28 17:50

    If you are interested in the first pair of comments, you could start with looking for the first comment:

    //comment()[.=' begin content ']/following::*[not(preceding::comment()[.=' end content '])]
    

    I.e.:

    //comment()[1][.=' begin content ']           <-- look for first suitable comment
        /following::*                             <-- take all following nodes
             [not(preceding::comment()[.=' end content '])] <-- satisfying condition there is no preceding "end comment"
    

    0 讨论(0)
提交回复
热议问题