antchfx / htmlquery

htmlquery is golang XPath package for HTML query.
https://github.com/antchfx/xpath
MIT License
739 stars 74 forks source link

Using Libraries to Convert HTML to XPath #43

Closed ProfessorManhattan closed 3 years ago

ProfessorManhattan commented 3 years ago

Hey, this is not an issue but I have been unable to understand why there are not many reputable packages that advertise the ability to turn CSS/HTML to XPaths. Can I use this library to convert CSS to an XPath?

zhengchun commented 3 years ago

No, this is an XPath package for XML/HTML/JSONdocuments query using XML query syntax. CSS Selector is another query syntax, there are cannot work together.

ProfessorManhattan commented 3 years ago

@zhengchun -- shouldn't it be possible to convert a CSS selector to an XPath as long as the CSS selector only returns one element?

zhengchun commented 3 years ago

You can do this in manually If you known CSS selector syntax and XPath syntax.

For example:

ProfessorManhattan commented 3 years ago

Hey @zhengchun --- thanks but if I do anything manually then my computer becomes the boss -- trying to ensure the opposite. There are a few libraries, the most popular of which is in PHP:

https://github.com/symfony/css-selector

And here's one in Node.js (with a lot less stars):

https://github.com/css2xpath/css2xpath

zhengchun commented 3 years ago

https://github.com/PuerkitoBio/goquery