如何通过Array获取所有文本

时间:2016-08-12 14:38:32

标签: ruby cucumber

Array to get all text

<p ng-if="!me.admin" class="sv ng-binding ng-scope" ng-repeat="x in user.groups | orderBy">NASS InfoPass Scheduler</p>

<p ng-if="!me.admin" class="sv ng-binding ng-scope" ng-repeat="x in user.groups | orderBy">NASS Adjudications Scheduler</p>

如何使用class="sv ng-binding ng-scope"作为数组来获取文本?

1 个答案:

答案 0 :(得分:0)

使用Nokogiri,您可以将文本提取为

require 'nokogiri'

# suppose you store your HTML text in variable `html'
html = <<EOF
  <p ng-if="!me.admin" class="sv ng-binding ng-scope" ng-repeat="x in user.groups | orderBy">NASS InfoPass Scheduler</p>
  <p ng-if="!me.admin" class="sv ng-binding ng-scope" ng-repeat="x in user.groups | orderBy">NASS Adjudications Scheduler</p>r</p>
EOF

doc = Nokogiri::HTML(html)
p doc.css('.sv.ng-binding.ng-scope').map(&:text)
#=> ["NASS InfoPass Scheduler", "NASS Adjudications Scheduler"]