Undefined namespace prefix in Nokogiri and XPath

后端 未结 1 396
情话喂你
情话喂你 2020-12-11 17:43

I am trying to parse Youtube Gdata to see if video with given id exists. But there isn\'t normal tag but with namespace. On the link http://gdata.youtube.com/feeds/api/video

相关标签:
1条回答
  • 2020-12-11 18:03

    I'm not sure why, but it seems that you have to drop the namespace prefix to get the node:

    xmlfeed.at_xpath("//totalresults")
    

    Also note that I added the double forward slash, which scopes the search over the whole document (it won't work without it).

    UPDATE:

    Based on this answer: How do I get Nokogiri to understand my namespaces? I'd guess that the namespace (openSearch:totalResults) is not correctly declared as an attribute on the root node of the document, and hence Nokogiri is just ignoring it, which is why the selector above works but the namespaced one doesn't.

    0 讨论(0)
提交回复
热议问题