Created
September 14, 2016 05:40
-
-
Save lmansur/b110465647aefabf8f7924590fd58405 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mechanize' | |
# Adiciona items ao array | |
def addItem(item, items, category) | |
image = item.at('img').attr('src') | |
name = item.at('h2').text.strip | |
rarity = item.at('.rlg-items-item-rarity').text.strip | |
items << { name: name, category: category.to_s, rarity: rarity, image: 'https://rocket-league.com'+image } | |
end | |
# Adiciona decals ao array | |
def addItemDecals(item, items, category) | |
image = item.at('img').attr('src') | |
name = item.at('h2').text.strip | |
rarity = nil | |
items << { name: name, category: category.to_s, rarity: rarity, image: 'https://rocket-league.com'+image } | |
end | |
# categorias e respectivos links | |
categories = {trails:'https://rocket-league.com/items/boosts', toppers:'https://rocket-league.com/items/toppers', | |
bodies:'https://rocket-league.com/items/bodies', antennas:'https://rocket-league.com/items/antennas', | |
wheels:'https://rocket-league.com/items/wheels', decals:'https://rocket-league.com/items/decals'} | |
agent = Mechanize.new | |
agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE # OPENSSL BUGADO NO WINDOWS, TIVE QUE TIRAR O CHECK | |
items = [] | |
categories.each do |key, value| | |
page = agent.get(value) | |
if key == :decals | |
#decals não tem rarity, funcao especial para ele | |
page.search('.rlg-items-item').each do |item| | |
addItemDecals(item, items, key) | |
end | |
else | |
page.search('.rlg-items-item').each do |item| | |
addItem(item, items, key) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment