G
G
ghostku2015-11-14 22:20:20
Python
ghostku, 2015-11-14 22:20:20

How to get only those elements after which there are certain elements in xpath?

Good afternoon. There is the following piece of the web page

<div id='X'><p>Text 1</p><br><font color="black"><b>Value 1</b></font></div>
<div id='X'><p>Text 2</p><br><font color="black"/></div>
<div id='X'><p>Text 3</p><br><font color="black"><b>Value 3</b></font></div>
<div id='X'><p>Text 4</p><br><font color="black"/></div>

As a result, you need to get an array of pairs:

I can’t figure out how to use xpath to select only those tags after which there is the structure I need
Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nirvimel, 2015-11-14
@ghostku

xpath('//div[@id="x" and font/b]/p[1]'), xpath('//div[@id="x"]/font[1]/b[1]')

The function itself and the call format depend on the library used, of course.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question