lib/crypto_price/scraper.rb in crypto_price-0.1.4 vs lib/crypto_price/scraper.rb in crypto_price-0.1.5

- old
+ new

@@ -1,21 +1,25 @@ class CryptoPrice::Scraper - def self.scrape_coinmarketcap - #binding.pry - #doc = Nokogiri::HTML(open("https://coinmarketcap.com")) - #doc.css("tbody.span").text.split("$").select{ |k| k.length > 0 } - doc = Nokogiri::HTML(open("https://coinstats.app/?pagesize=50&page=1")) - doc.css("td.data-cell.mobile-last").text.split("$").select{ |k| k.length > 0 } - end + # def self.scrape_coinmarketcap + # binding.pry + # #doc = Nokogiri::HTML(open("https://coinmarketcap.com")) + # #doc.css("tbody.span").text.split("$").select{ |k| k.length > 0 } + # doc = Nokogiri::HTML(open("https://coinstats.app/?pagesize=50&page=1")) + # doc.css("td.data-cell.mobile-last").text.split("$").select{ |k| k.length > 0 } + # end + + - def self.scrape_coinlib - doc = Nokogiri::HTML(open("https://coinlib.io/coins")) - prices = self.scrape_coinmarketcap - names = doc.css("div.tbl-currency").text.split("\n").select{ |k| !k.include?("[") && k.length > 0} - symbols = doc.css("span.tbl-coin-abbrev").text.gsub("]", "").split("[").select{|k| k.length > 0} - changes = doc.css("span.tbl-price.pr-change").text.split("%").select{|k| k.length > 0} - marketcaps = doc.css("span.mob-info-value").text.split("$").select{|k| k.length > 0} + # https://coindataflow.com/en seems to have a well designed fornt end with strcutured html and css + def self.scrape_coins #binding.pry + doc = Nokogiri::HTML(open("https://coindataflow.com/en")) + names = doc.css("tbody tr td[3]").text.gsub(" ", "").split("\n").select{|k| k.length > 0} + symbols = doc.css("tbody tr td[4]").text.gsub(" ", "").split("\n").select{|k| k.length > 0} + prices = doc.css("tbody tr td[5]").text.gsub(" ", "").split("\n").select{|k| k.length > 0} + changes = doc.css("tbody tr td[6]").text.gsub(" ", "").split("\n").select{|k| k.length > 0} + marketcaps = doc.css("tbody tr td[12]").text.gsub(" ", "").split("\n").select{|k| k.length > 0} + index = 0 while index < names.length && index < symbols.length symbol = symbols[index] name = names[index] price = prices[index] \ No newline at end of file