James-LG / Skyscraper

Rust library for scraping HTML using XPath expressions
MIT License
30 stars 3 forks source link

xpath: Cannot select attribute? #15

Closed SuperKenVery closed 6 months ago

SuperKenVery commented 11 months ago

For example,

document:

<input name="hi" id="in"></input>

I hope

//*[@id="in"]//@name

to return a Vec containing hi, but in fact it returns an empty Vec.

This syntax works in python lxml, so I guess it's a problem with this library?

James-LG commented 11 months ago

Yes, attribute selection with XPath has not yet been implemented, but it is on my todo list.

In the meantime you can just get the node with XPath and use the library to retrieve the attributes. See the docs here.