Skip to content

Instantly share code, notes, and snippets.

@Beyarz
Created April 10, 2021 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Beyarz/97804ab20e6ac794dfbcceed15fdcadd to your computer and use it in GitHub Desktop.
Save Beyarz/97804ab20e6ac794dfbcceed15fdcadd to your computer and use it in GitHub Desktop.
Scrapes all the top 100 coins from coinmarketcap.
begin
require "open-uri"
rescue LoadError
system "gem install openurl"
end
begin
require "nokogiri"
rescue LoadError
system "gem install nokogiri"
end
# Variables
align1 = 3
align2 = 5
align3 = 15
alignx = 17
x = 1
url = "https://coinmarketcap.com/"
# Parsing
keepTrack = []
@doc = Nokogiri::HTML(open(url))
newSite = 0
parse = true
while parse == true
begin
array = @doc.css("tr")[x].text.delete(" ").split("\n")
rescue NoMethodError
parse = false
end
rawArr = []
parsedArr = []
for each in array
if each == ""
next
else
rawArr.push(each)
end
end
parsedArr = rawArr.uniq
begin
keepTrack << "| #{parsedArr[0].center(align1)} | #{parsedArr[1].center(align2)} | #{parsedArr[4].center(alignx)} | #{parsedArr[7].center(align3)} |"
rescue NoMethodError
end
x = x + 1
end
# Removes all the dupes
output = keepTrack.uniq
for row in output
puts row
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment