问题描述
这是我成功抓取的页面的结果:
Here is the result of the page I successfully crawled:
问题是我只得到了数字!没有分离.我的目标是将它们分开和排序.
The problem is that I've only been given numbers! There is no separation. My goal is to separate and sort them.
这些数字中的每一个都代表着某种意义.但让我们拿前三个.5553为玩家等级,2591为玩家等级,1287238956为玩家经验值.
Each of these numbers means something. But let's take the first three. 5553 is the player's rank, 2591 is the player's level, and 1287238956 is the player's experience points.
如何以这样的格式(如表格)显示此信息?
How do I display this information in a format like this (like a table)?
Skill Rank Level Experience
Overall 5553 2591 1287238956
这是我的 PagesController:
Here is my PagesController:
class PagesController < ApplicationController
def home
require 'open-uri'
@username = "brink"
@url = "http://hiscore.runescape.com/index_lite.ws?player=#{@username}"
@doc = Nokogiri::HTML(open(@url))
end
def help
end
end
这是我的家庭视图:
<h1>Welcome to xpTrack</h1>
<%= @doc.text %>
我有哪些选择?
我尝试过的和正在做的
- 我研究了
split
方法,但显然只是适用于数组? - 我还注意到,每个分隔之间都有一个空格我需要提出的观点.猜猜现在这只是一个能够呼叫其中一个单位.
- 目前正在尝试将
@doc
转换为字符串并以某种方式用空格将其分开. - ^^^ 那肯定没用.
- I have looked into the
split
method, but that apparently onlyworks for arrays? - I have also noticed that there is a space between every separationpoint I need to make. Guess now it's just a matter of being able tocall upon one of those units.
- Currently trying to convert
@doc
into a string and somehow break it apart by spaces. - ^^^ Well that sure didn't work.
推荐答案
可枚举#each_slice这可以帮助您构建表.在你的情况下
来自另一个答案的数据
Enumerable#each_slicethis help you for build table. In you case
data from another answer
=> data = "5553,2591,1287238956 5553,2591,1287238956 5553,2591,1287238956 5553,2591,1287238956"
=> data.split(' ').each_slice(3) { |a| puts a }
=> 5553,2591,1287238956
5553,2591,1287238956
5553,2591,1287238956
5553,2591,1287238956
这篇关于对抓取的信息进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!