-
Notifications
You must be signed in to change notification settings - Fork 92
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 generating unique selector from multiple elements? #45
Comments
@ScrapeFlare I'm not sure I understand what you mean. Can you please give me an example? |
It sounds like they might mean something I would find helpful, which is a way to say "here is a given selector, which matches one or more elements, and also here is a specific one of those elements - please take the existing selector and, if necessary, add to it so that it only matches that one element". |
@jribbens Can you please provide me with an example of what selectors you're trying to get? |
Well perhaps you might say Basically my use case for the module requires thinking across time, as the HTML file may change. Now obviously there is no way at all to guarantee that a selector created for a previous version of the file will still relate to "the same" element in the new version (whatever we might mean by that exactly), but there are ways we can make that more likely, and those include avoiding making the selector too short and avoiding too much reliance on |
If I'm not wrong, I think what they're trying to suggest is a feature like The reason I don't like using the I definitely wouldn't mind working with you on this feature, so please do hit me up. |
@AfrazHussain I'm not sure this is the same as what @jribbens describes. Anyway, it is easy to create a function that returns a list of selectors for a list of provided elements. Just use this: function getMultipleCssSelectors (elements = [], options = {}) {
return elements.map((element) => getCssSelector(element, options))
} |
@fczbkk Thanks for your reply, and thank you for this library. From what I understood, the idea isn't to create a list of single unique selectors given an array of elements, but it is rather to create a single selector that would select all of the elements selected. I'll give you an example, suppose I want to scrape all the item names on this website. Now if I pass the element in the The Webscraper extension does this very nicely where you can select a single element, or select multiple elements by holding the control key, and it will give a unique selector for the multiple items that you've selected. Please let me know if some of this doesn't make sense and I'll be happy to clarify. :) Again thanks for you reply. 👍 |
I can't speak to what @ScrapeFlare was wanting, but what I'm doing is creating a selector that uniquely identifies a single element on the page, but does so in a way that means we have a decent chance of the selector still indicating that same element even if the page then changes somewhat (e.g. if we come back to the page a month later). As it stands, if you have, say, only one image on a page then this library will return a very short but very fragile selector of just I've written my own library to do this now, but I just thought I'd clarify. |
@jribbens Thanks for the explanation, I get it now. |
I had an idea on how to implement this. It required a lot more of rewrites than I originally thought. But it seems to be working. Since More info in documentation: |
Is such a feature on the roadmap?
The text was updated successfully, but these errors were encountered: