How to build a web scraper in Ruby — a COVID-19 live data example.

  1. First, create a new directory/folder and cd into it.
mkdir corona-scraper && cd corona-scraper
bundle init
touch scraper.rb
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)
byebug
end
ruby scraper.rb
your terminal should look something like this
   total_countries = parsed_page.css
('table#main_table_countries_today >
tbody > tr').map(&:text).count

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store