Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for :has() selector #169

Open
124C41p opened this issue Feb 8, 2024 · 4 comments
Open

Support for :has() selector #169

124C41p opened this issue Feb 8, 2024 · 4 comments
Labels
C-feature-request Category: feature request

Comments

@124C41p
Copy link

124C41p commented Feb 8, 2024

Hi, do you plan to support the :has() selector? To my understanding, this css keyword is needed for selecting objects based on the parent of another known object.

Consider the following example:

<div>
    <div id="foo">
        Hi There!
    </div>
</div>
<ul>
    <li>first</li>
    <li>second</li>
    <li>third</li>
</ul>

In order to select the second list item, I would like to use the following selector:

let selector = Selector::parse("div:has(div#foo) + ul > li:nth-child(2)").unwrap();

This line however panics as of scraper version 0.18.1.

@adamreichold
Copy link
Contributor

I think this is still missing support in our upstream dependency selectors dependency, at least in the version published on crates.io.

@cyqsimon
Copy link

+1. I'm trying to scrape Wikipedia, which has this sort of nesting. For example:

<h2>
  <span class="mw-headline" id="Registered_ports">Registered ports</span>
  <!-- ... -->
</h2>

This selector: h2:has(#Registered_ports) ~ .wikitable.sortable would pick the first table after this h2, which is a good way to locate the content in lieu of a distinctive id/class on the table itself.

@cfvescovo cfvescovo added the C-feature-request Category: feature request label Feb 22, 2024
@nicoburns
Copy link

nicoburns commented Feb 29, 2024

From what I can see selectors 0.25 (published to crates.io) does have :has support. See https://docs.rs/selectors/latest/selectors/parser/enum.Component.html#variant.Has Although there seem to be performance improvements in more recent unreleased commits.

@nathaniel-daniel
Copy link

servo/servo#25133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: feature request
Projects
None yet
Development

No branches or pull requests

6 participants