Created
April 10, 2021 00:46
-
-
Save Beyarz/97804ab20e6ac794dfbcceed15fdcadd to your computer and use it in GitHub Desktop.
Scrapes all the top 100 coins from coinmarketcap.
This file contains 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
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