Parsing HTML using Xpath with Javascript

99封情书 提交于 2019-12-23 18:19:50

问题


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?


回答1:


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

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




回答2:


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.



来源:https://stackoverflow.com/questions/11580362/parsing-html-using-xpath-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!