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

Does this support xpath selectors ? #19

Open
mdrokz opened this issue Jul 24, 2023 · 4 comments
Open

Does this support xpath selectors ? #19

mdrokz opened this issue Jul 24, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@mdrokz
Copy link

mdrokz commented Jul 24, 2023

Hi i wanted to know if this supports xpath selectors like this "//h1[contains(text(),'Search Results')]/following-sibling::div[1]/div" ?

@fefit
Copy link
Owner

fefit commented Jul 26, 2023

@mdrokz sorry for the late reply, this crate does not support xpath selectors. If this requirement is common, I plan to take the time to add this feature recently.

@mdrokz
Copy link
Author

mdrokz commented Jul 26, 2023

@mdrokz sorry for the late reply, this crate does not support xpath selectors. If this requirement is common, I plan to take the time to add this feature recently.

Hey thanks for the reply it will be really helpful to scrape websites that have randomly generated class names and ID. I can help out in implementing the feature If you can guide me thanks.

@fefit
Copy link
Owner

fefit commented Jul 31, 2023

@mdrokz I have added a new feature branch to support xpath selectors. The query methods in this crate used to only accept the type &str as a selector parameter, so i add a new trait TryIntoSelector to allowed more types that implement the trait as a selector too. However, the whole logic of query methods is based on css selectors, it is not easy to add the processing logic of xpath selector. I think a simple but not so efficient way is to convert the xpath selectors into the corresponding css selectors, a small number of xpath selectors may not have corresponding css selectors, this may require expanding the capabilities of css selectors. It will takes a lot of work to fully support xpath selectors, if you have a better solution, we can discuss it here.

Thank you very much for your willingness to contribute code to this crate. You can fork the repo, and checkout a new branch from the feature branch, add code to support xpath selectors and also some unit tests code, then make a PR.

I'm worried that it may take up a lot of your time to implement this feature. If you don't have much time on this, you can also tell me, i can do some of the work together. Thanks again!

@mdrokz
Copy link
Author

mdrokz commented Aug 1, 2023

@mdrokz I have added a new feature branch to support xpath selectors. The query methods in this crate used to only accept the type &str as a selector parameter, so i add a new trait TryIntoSelector to allowed more types that implement the trait as a selector too. However, the whole logic of query methods is based on css selectors, it is not easy to add the processing logic of xpath selector. I think a simple but not so efficient way is to convert the xpath selectors into the corresponding css selectors, a small number of xpath selectors may not have corresponding css selectors, this may require expanding the capabilities of css selectors. It will takes a lot of work to fully support xpath selectors, if you have a better solution, we can discuss it here.

Thank you very much for your willingness to contribute code to this crate. You can fork the repo, and checkout a new branch from the feature branch, add code to support xpath selectors and also some unit tests code, then make a PR.

I'm worried that it may take up a lot of your time to implement this feature. If you don't have much time on this, you can also tell me, i can do some of the work together. Thanks again!

Hey @fefit thank you for taking your time to work on this feature, i will fork the project and checkout the branch when i get some time im currently working a full time job so i will be doing this on my spare time i will let you know if i encounter any issues or need your help once i see the branch. Thanks!

@fefit fefit added the enhancement New feature or request label Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants