1

I am new to R and trying to scrape the map data from the following webpage: https://www.svk.se/en/national-grid/the-control-room/. The map is called "The flow of electricity". I am trying to scrape the capacity numbers (in blue) and the corresponding countries. So far I could not find a solution on how to find the countries' names in the HTML code and consequently scrape them.

Here is an example of data I need: enter image description here

Would you have any idea?

Thanks a lot in advance.

2 Answers 2

2

The data is not in the table, hence we need to extract all the information individually.

Here is a way to do this using rvest.

library(rvest)
url <-'https://www.svk.se/en/national-grid/the-control-room/'

webpage <- url %>% read_html() %>%html_nodes('div.island')

tibble::tibble(country = webpage %>% html_nodes('span.country') %>% html_text(),
                watt = webpage %>% html_nodes('span.watt') %>% html_text() %>% 
                         gsub('\\s', '', .) %>% as.numeric(),
                unit = webpage %>% html_nodes('span.unit') %>% html_text())


#  country    watt unit 
#  <chr>     <dbl> <chr>
#1 SWEDEN     3761 MW   
#2 DENMARK     201 MW   
#3 NORWAY     2296 MW   
#4 FINLAND    1311 MW   
#5 ESTONIA     632 MW   
#6 LATVIA      177 MW   
#7 LITHUANIA  1071 MW   
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Ronak, thanks a lot for your answer. I meant the figures from the map though. So, each individual flow from one country to another. Should look something like FI > EE 1031MW. I cannot find the "FI>EE" element in html. Regards.
I don't see anything like FI > EE 1031MW. on the map. There are values like €6.89 on the map.
I uploaded the screenshot in the problem description.
0

The flow data comes from an API call so you need to make an additional xhr (to an url you can find in the network tab via dev tools ) to get this data. You don't need to specify values for the timestamp (Ticks) and random (rnd) params in the querystring.

library(jsonlite)

data <- jsonlite::read_json('https://www.svk.se/Proxy/Proxy/?a=http://driftsdata.statnett.no/restapi/PhysicalFlowMap/GetFlow?Ticks=&rnd=')

As a dataframe:

library(jsonlite)
library (plyr)

data <- jsonlite::read_json('https://www.svk.se/Proxy/Proxy/?a=http://driftsdata.statnett.no/restapi/PhysicalFlowMap/GetFlow?Ticks=&rnd=')

df <- ldply (data, data.frame)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.