causal-agent / scraper

HTML parsing and querying with CSS selectors
https://docs.rs/scraper
ISC License
1.81k stars 100 forks source link

How to select in pairs? #127

Closed extf33 closed 4 months ago

extf33 commented 1 year ago

How to select only pre.CCC with "Hello, Rust!" immediately before it, in the code below?

<section id="AAA">
    <p class="BBB">Hello, Rust!</p>
    <pre class="CCC">...</pre> ----------> O
    <p>...</p>
    <pre class="CCC">...</pre> ----------> X
</section>
adamreichold commented 1 year ago

Did you try p.BBB + pre.CCC which selects the pre.CCC if it is immediately preceded by p.BBB? If you try select based on Hello, Rust!, then this not yet possible with CSS selectors AFAIK.