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

Can I use it with html5ever? #73

Open
LeMoussel opened this issue Jul 7, 2016 · 4 comments
Open

Can I use it with html5ever? #73

LeMoussel opened this issue Jul 7, 2016 · 4 comments

Comments

@LeMoussel
Copy link

LeMoussel commented Jul 7, 2016

Can I use sxd-xpath with html5ever to find node in HTML document?

For example:

let html_file =  Path::new("cocon1.html").to_path_buf();
let dom = parse_document(RcDom::default(), Default::default())
                .from_utf8()
                .from_file(&html_file)
                .unwrap();
let html_content = document.to_string();
@shepmaster
Copy link
Owner

No, but this could be interesting to investigate. I don't think it would be very easy though, as I believe (but have not verified) that the underlying access to the DOMs is not the most similar.

@mildred
Copy link

mildred commented Aug 20, 2017

Does sxd-xpath depends directly on a sxd-document object or does it depends on a trait which is implemented using sxd-document but can be re-implemented for any parser with similar access? If not, is that complicated to do so?

@shepmaster
Copy link
Owner

Does sxd-xpath depends directly on a sxd-document object

Yes, basically everywhere uses a concrete sxd_xpath::nodeset::Node which itself refers to 7 concrete types from sxd-document. The code then matches on that in various places and uses methods on those types. The Node is also a public API.

I don't have an answer for "is it complicated". My gut feeling is that it would be, but sometimes the only way to find out is to just try.

@carlolefou
Copy link

@shepmaster I needed to evaluate xpaths against html for scraping so I wrote this helper library to bridge html5ever with sxd-document. This is pretty much my first real rust code so, if you have some time, please take a look and send any feedback my way. thanks! https://github.com/carlolefou/sxd-html

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

No branches or pull requests

4 participants