nokogiri xpath attribute - strange results

人走茶凉 提交于 2019-12-06 08:04:45

The problem is the leading double-slash in xpath('//FIELD/TOKEN'), which tells nokogiri to match nodes not relative to this node, but across the whole document regardless of location. To match relative to the node itself, you have to remove the double-slash:

tbegin = record.xpath('FIELD//TOKEN')

As additional clarification, the reason tbegin = record.css('TOKEN') works is record is providing the top node where the search will begin. 'TOKEN' doesn't force a search at the root of the document, unlike //FIELD/TOKEN, which would do that.

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