D
D
Dmitry Sviridov2020-01-08 23:08:50
css
Dmitry Sviridov, 2020-01-08 23:08:50

How to write a css selector "paragraphs going between two headings"?

I understand that the question sounds strange, but I need it for the Scrapy parser, so I cannot add any classes to the elements myself. You need to select all paragraphs between two h2 tags. How to do it right? If you do something like response.css('h2:contains("Story") + p').get() , then only the first paragraph after the h2 heading with the text "Story" will be selected. How to select all paragraphs (their number is arbitrary) until the next h2, and not just the first one? Here is an html example:

<h2>Рассказ</h2>
<p>Привет, Вася!</p>
<p>Как дела?</p>
<h2>О чем рассказ</h2>
<p>Я поздоровался с Васей</p>

Here I need, roughly speaking, to apply the style only to these paragraphs:
<p>Привет, Вася!</p>
<p>Как дела?</p>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dom1n1k, 2020-01-08
@dimuska139

If there are few paragraphs, then you can try this crutch:
But in general, there is no "correct" solution in pure CSS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question