0

我需要从特定页面中的所有跨度中读取名为“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

但它抛出此错误':未定义的局部变量或方法'contents' for main:Object(NameError)'

任何人都可以帮我阅读这个数据内容的价值吗?

4

1 回答 1

3

您可以像获取其他属性一样获取数据以及 aria 属性。唯一的区别是方法名称使用下划线而不是破折号。

要获取 data-contents 属性,您可以:

puts span.data_contents
于 2016-02-11T13:55:29.600 回答