Here's one tricky scenario:
#target ~ p {
background: green;
color: white;
}
<h1 id="target">Title</h1>
<span>Some description</span>
<p>Yes</p>
<p>Yes</p>
<h1>Another Title</h1>
<span>Some description</span>
<p>No</p>
<p>No</p>
Does xpath allow selecting siblings but stop at a point? I would like to select the two <p>
s under the first <h1>
but not the ones under the second <h1>
. Modifying the HTML is not possible as I am doing some web scraping and I am looking for a quick and dirty way of extracting data from paragraphs under a certain heading:
paragraphs = target.select("~ p")
`s under the first `
` but ones under the second `
– chriskirknielsen Feb 16 '18 at 14:40`".