# How to import a COVID-19 data table from a website into a Mathematica notebook

This link https://www.worldometers.info/coronavirus/ provides daily cases of COVID-19 across all the countries. Is there an easy way to retrieve this table into a Mathematica notebook?

I tried:

Import["https://www.worldometers.info/coronavirus/", "HTML"]


which retrieves the data in an unformatted structure.

Thanks.

• Consider using another source with friendlier formatting, such as the European Centre for Disease Control and Prevention's data set, which is available as CSV, XLM, or JSON; or the database maintained by Our World in Data, which is explicitly freely available in various formats as well. Nov 27, 2020 at 19:26
• @MarcoB: I tried to import the data for a selected set of countries using MMA but the results are not so impressive because there are many text I am not interested in. I have a list of countries {Turkey, USA, China} for which I like to retrieve the data for several variables: {Total Cases, New Cases, Total Deaths, Total Recovered, Population}. How can I create this table using MMA code? Nov 27, 2020 at 20:28

( Not an answer, extended comment.)

In this particular case (the code of that site today):

lsData = Import["https://www.worldometers.info/coronavirus", "Data"]


works. Meaning, the data can be investigated further using Cases, Part, and TableForm (or other tabular formatting function.)

For example, this list

lsTbls = Cases[
lsData, {{"#", "Country, Other", "Total Cases", "New Cases",
"Total Deaths", ___}, ___}, \[Infinity]];
Length[lsTbls]

(* 3 *)


has three elements that (seem to) correspond to "Now", "Yesterday", "2 days ago" shown in the site.

Note, the data has a continent column, but the import above did not align the rows/columns properly. Meaning, further data massaging / wrangling is needed.

Read the data not with "HTML" but with "Data":

dat = Import["https://www.worldometers.info/coronavirus/", "Data"];


Now you have all data in one big mess and you need to pick it apart.

E.g.:

TableForm[tt[[2, 2, 2, 1, 2]], TableHeadings -> {None, tt[[2, 2, 2, 1, 1]]}]


Or:

TableForm[tt[[2, 2, 2, 2, 2]], TableHeadings -> {None, tt[[2, 2, 2, 2, 1]]}]


E.t.c.