A
A
Alex Smith2018-11-16 18:44:09
XPath
Alex Smith, 2018-11-16 18:44:09

How to pick up text using Xpath?

We have the following html:

<p>
    рездел1: <code>1111<br class="inline"></code>
    рездел2: <strong>222<br class="inline"></strong>
    рездел3: <code>333<br class="inline"></code>
    рездел4: <strong>4444<br class="inline"></strong>
</p>

It is necessary to push off from section1 to pick up what is in the "code" tag, while the number of sections is unknown.
Same thing with section 2 where you need to pick up text() in the strong tag

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Fov, 2018-11-23
@sasnnick

Everything is simple there. Treat text like ordinary nodes:

p/strong[normalize-space(preceding-sibling::text()[1]) = 'рездел2:']/text()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question