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

Find better selectors #24

Open
lorey opened this issue Jun 24, 2022 · 2 comments
Open

Find better selectors #24

lorey opened this issue Jun 24, 2022 · 2 comments

Comments

@lorey
Copy link
Owner

lorey commented Jun 24, 2022

Currently, we just use the next best selector we find, starting from generic to specific. But too generic selectors are bad, e.g. div most likely has no meaning, and on the other hand, to specific selectors like the full path are likely too specific and will break.

Maybe there's a heuristic for good selectors. An idea:
What if we compute selectivity for each selector, e.g. how unique this selector is on the whole page. Would prefer ids and unique classes and discourage generic selectors. We then take the most selective but simplest selector.

@entrptaher
Copy link

Converting a dynamic selector to a * based selector may work.

decentralizeCss(`h2.heading--2eONR.heading-2--1OnX8.title--3yncE.block--3v-Ow`)

// h2[class*="heading--"][class*="heading-2--"][class*="title--"][class*="block--"]

Ofc it depends on the implementation of this function, I tested it a few times and it worked.

@lorey
Copy link
Owner Author

lorey commented May 1, 2023

I think with the soupsieve implementation, that's computationally very expensive. For something java-based with xslt, it might make more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants