Skip to content

Instantly share code, notes, and snippets.

@onedebos
Last active March 30, 2020 12:18
Show Gist options
  • Save onedebos/fb84c30dd4f149a1db6f200ca034889b to your computer and use it in GitHub Desktop.
Save onedebos/fb84c30dd4f149a1db6f200ca034889b to your computer and use it in GitHub Desktop.
require 'httparty'
require 'nokogiri'
require 'byebug'
require 'json'
def all_countries
unparsed_page = HTTParty.get('https://www.worldometers.info/coronavirus/')
parsed_page = Nokogiri::HTML(unparsed_page)
records = []
total_countries = parsed_page.css('table#main_table_countries_today > tbody > tr')
.map(&:text).count
i = 1
while i < total_countries
record = parsed_page.css("table#main_table_countries_today > tbody >
tr[#{i}]").text
record = record.split("\n")
record_hash = { "name": record[1], "total_cases": record[2],
"new_cases": record[3],
"total_deaths": record[4],
"new_deaths": record[5],
"total_recovered": record[6],
"active_cases": record[7],
"first_case": record[8] }
records << record_hash
i += 1
end
records
byebug
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment