how to use nokogiri methods .xpath & .at_xpath

a 夏天 提交于 2019-12-05 13:16:26
Simone Carletti
  1. // means every node at every level so it's much more expensive compared to /
  2. you can use * as placeholder.
  3. No, you can make an XPath query, get the element then call the nokogiri text method on the node
  4. Sure you can. Have a look at this question and my benchmark file. You will see an example of at_xpath.

I found you often use text() expression. This is not required using Nokogiri. You can retrieve the node then call the text method on the node. It's much less expensive.

Also keep in mind Nokogiri supports .css selectors. They can be easier if you are working with HTML pages.

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