如何通过Array获取所有文本 [英] How to get all text by Array

查看:571
本文介绍了如何通过Array获取所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数组可获取所有文字

 < p ng-if =!me.adminclass =sv ng-binding ng-scopeng-repeat =x in user.groups | orderBy > NASS InfoPass计划程序< / p> 

< p ng-if =!me.adminclass =sv ng-binding ng-scopeng-repeat =x in user.groups | orderBy> NASS Adjudications Scheduler< ; / p>

如何使用 class =sv ng-binding ng-scope

使用 .nokogiri.org /rel =nofollow> Nokogiri 您可以将文本解压缩为

  require'nokogiri '

#假设您将HTML文本存储在变量html中
html =<< EOF
< p ng-if =!me.admin类=sv ng-binding ng-scopeng-repeat =x in user.groups | orderBy> NASS InfoPass Scheduler< / p>
< p ng-if =!me.adminclass =sv ng-binding ng-scopeng-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]


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>

How can I use class="sv ng-binding ng-scope" as a Array to get text?

解决方案

With Nokogiri you can extract the text as

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"]

这篇关于如何通过Array获取所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆