Parsing HTML using Xpath with Javascript

html-agility-pack html-parsing javascript jquery xpath

Question

In .NET there is a lovely library that allows me to easily parse an external html page using xpath queries (HTML Agility Project) - the problem is I have to do that client-side, so only javascript. Is there any way to do that?

Accepted Answer

jQuery also supports xPath selector as well CSS, you can get more information from the link below.

http://docs.jquery.com/DOM/Traversing/Selectors


Popular Answer

You can try it https://github.com/andrejpavlovic/xpathjs

Actually there are a lot of it and there is an window.evaluate method by default.

But the reason why mostly all frameworks using selectors like jQuery/Mootols/Dojo (Sizzle) is that in all modern modern browsers it`s supports almostly native and gets fall back if it doesn't. So in most ways it's faster.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why