Predictive Hacks

Web Scraping worldometers for Coronavirus

One of the most popular web pages about Covid-19 is the worldometers which provides a detailed report about Coronavirus cases by country. Today, we will show how we can use R to Web Scrape the summary table of the site.

```library(tidyverse)
library(rvest)

url <- "https://www.worldometers.info/coronavirus/"

# There are some "+" symbols and the ","
# for the thousand separators that we wan to remove them
my_table[]<-lapply(my_table, function(x) (gsub("\\,|\\+", "", (x))))

# convert all but the first and last column to numeric

my_table[,c(3:12)] <- sapply(my_table[c(3:12)],as.numeric)
```

Since we got the data and we cleaned them, we can provide some statistics like:

Q: Which are the top 10 countries in Deaths per 1M Population?

```my_table%>%arrange(-`Deaths/1M pop`)%>%
select(`Country,Other`,`Deaths/1M pop`)%>%

```
``````   Country,Other Deaths/1M pop
1     San Marino          1032
2        Andorra           375
3          Spain           363
4          Italy           322
5        Belgium           311
6         France           212
7   Sint Maarten           210
8    Netherlands           160
9             UK           156
10   Switzerland           126``````

8 thoughts on “Web Scraping worldometers for Coronavirus”

1. I am very glad about so such analysis
but output shows only pop values if possible guide me
warm regards

• They changed the format of the table. I fixed it now.

1: In lapply(X = X, FUN = FUN, …) : NAs introduced by coercion
2: In lapply(X = X, FUN = FUN, …) : NAs introduced by coercion
3: In lapply(X = X, FUN = FUN, …) : NAs introduced by coercion
4: In lapply(X = X, FUN = FUN, …) : NAs introduced by coercion
>

• This means that some values like NA and N/A etc are converted to NAs. They also changed the format of the table. I fixed it now.

3. Hello,
If possible, could you post the fix.
Thanks

• Hi Roger, what fix?

4. Great code. Is there a way to get historical data from Worldometer?

• Thank you!

Get updates and learn from the best

Python

Creating Dynamic Forms with Streamlit: A Step-by-Step Guide

In this blog post, we’ll teach you how to create dynamic forms based on user input using Streamlit’s session state

Python

How to Connect Wikipedia with ChatGPT and LangChain

ChatGPT’s knowledge is limited to its training data, which has the cutoff year of 2021. This implies that we cannot