我需要读取名为" data-contents"的属性的值。来自特定页面中的所有跨度
<span tabindex="0" title="" class="text-warning ng-isolate-scope" role="button" data-original-title="" data-toggle="popover" data-placement="top" data-html="true" data-contents="If you are not sure which type of occupation in the list to choose, please call us on (852) 2884 8888 and we'll be happy to help you." data-content="If you are not sure which type of occupation in the list to choose, please call us on (852) 2884 8888 and we'll be happy to help you." data-da-popover="" data-da-popover-id="daPopover1455178167018" data-container="body" data-trigger="focus"><img src="/app/ui/images/question-icon.png"> </span>
我写了以下代码,
b.spans.each do |span|
puts span.data-contents
end
但它抛出了这个错误&#39 ;:未定义的局部变量或方法`内容&#39; for main:Object(NameError)&#39;
有人可以帮助我阅读这些数据内容的价值吗?
答案 0 :(得分:3)
您可以像其他属性一样获取数据和咏叹调属性。唯一的区别是方法名称使用下划线而不是破折号。
要获取data-contents属性,您可以执行以下操作:
puts span.data_contents