对抓取的信息进行排序? [英] Sorting crawled information?

查看:28
本文介绍了对抓取的信息进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我成功抓取的页面的结果:

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 %>

我有哪些选择?

我尝试过的和正在做的

  1. 我研究了 split 方法,但显然只是适用于数组?
  2. 我还注意到,每个分隔之间都有一个空格我需要提出的观点.猜猜现在这只是一个能够呼叫其中一个单位.
  3. 目前正在尝试将 @doc 转换为字符串并以某种方式用空格将其分开.
  4. ^^^ 那肯定没用.
  1. I have looked into the split method, but that apparently only works for arrays?
  2. I have also noticed that there is a space between every separation point I need to make. Guess now it's just a matter of being able to call upon one of those units.
  3. Currently trying to convert @doc into a string and somehow break it apart by spaces.
  4. ^^^ Well that sure didn't work.

推荐答案

可枚举#each_slice这可以帮助您构建表.在你的情况下
来自另一个答案的数据

Enumerable#each_slice this 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

这篇关于对抓取的信息进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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