Class: Quiz::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/quiz/scraper.rb

Overview

scraper Class

Class Method Summary collapse

Class Method Details

.balon_d_or_playersObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/quiz/scraper.rb', line 10

def self.balon_d_or_players
    balon_d_or_url = "https://www.goal.com/es/noticias/todos-los-ganadores-del-balon-de-oro/wn19xivn1eh91t0jrslbzz5kq"
    balon_de_or_files = ".tableizer-table"
    players = self.scraper(balon_d_or_url,balon_de_or_files).map{|l|l.text.split(/\t|\*/).reject{|e|e.empty? || e.include?("(FIFA Balón de Oro)")}}
    2.times{players[0].shift}
    players[0][16] = "Lionel Messi"
    counter = 0
    all_players = []
    while counter < players[0].size
        all_players << {:winner => players[0][counter],:year => players[0][counter + 1]}
        counter += 2
    end
        all_players
end

.champion_leagueObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/quiz/scraper.rb', line 39

def self.champion_league
     champion_league_url = "https://en.wikipedia.org/wiki/List_of_European_Cup_and_UEFA_Champions_League_finals"
     champion_league_file  = "tbody"
     
     champions = self.scraper(champion_league_url,champion_league_file).map{|l|l.text.split("\n").reject{|e|e.empty?}}
     champions[0].shift
     champions.shift
     champions.shift
     10.times{champions[0].shift}
     23.times{champions[0].pop}
     7.times{champions[0].delete_at(145)}
     counter = 0
     all_teams = []
     while  counter < champions[0].size
        all_teams << {:year => champions[0][counter], :winner => champions[0][counter + 2], :score => champions[0][counter + 3], :runner_up => champions[0][counter + 5], :host => champions[0][counter + 6]} 
        counter += 8                       
     end
     all_teams
end

.scraper(url, clas) ⇒ Object



5
6
7
8
# File 'lib/quiz/scraper.rb', line 5

def self.scraper(url,clas)
    doc = Nokogiri::HTML(open(url))
    doc.css(clas)
end

.world_cupObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/quiz/scraper.rb', line 26

def self.world_cup
    world_cup_url = "https://www.foxsports.com/soccer/fifa-world-cup/history"
    world_cup = "tbody"
    world_cup = self.scraper(world_cup_url,world_cup).map{|l|l.text.split(/\r\n|\s{2,}/).reject{|e|e.empty?}}
    counter = 0 
    all_countries = []
    while counter < world_cup[0].size
        all_countries << {:year => world_cup[0][counter], :host => world_cup[0][counter + 1], :winner => world_cup[0][counter + 2], :runner_up => world_cup[0][counter + 3], :thirth_place => world_cup[0][counter + 4]}
        counter += 9
   end
   all_countries
end