Javier
Javier

Reputation: 332

Downloading table from website into R

I've been trying to download this table into R without success.

The code I'm using is this one

library(XML)
web_banrep <- "http://obieebr.banrep.gov.co/analytics/saw.dll?Go&Action=prompt&lang=es&NQUser=publico&NQPassword=publico&path=%2Fshared%2fSeries%20Estad%C3%ADsticas%2F1.%20Empleo%20y%20desempleo%2F1.1%20Serie%20hist%C3%B3rica%2F1.1.1.EMP_Total%20nacional&Options=rdf"
desemp     <-  readHTMLTable(web_banrep, header=T, which=1,stringsAsFactors=F)

I'd appreciate any help.

Upvotes: 0

Views: 184

Answers (1)

Rentrop
Rentrop

Reputation: 21507

If you just want that one table, a very handy tool for this kind of JS-reliant websites is:
Chrome Pipe (Plugin, Github)

With it you can get data from your currently rendered dom as you see it in your chrome-browser. I normally use

selectorgadget | text | pbcopy

which copies the Data to your clipboard

An alternativ is:

selectorgadget | text | gist

which gives you the link to a gist with your data. Here is yours:

https://gist.github.com/anonymous/3772146382b500195a22ba2b10962ffa

From there click on raw to get the url of your data. You can then parse it using R as follows:

gist_raw <- "https://gist.githubusercontent.com/anonymous/3772146382b500195a22ba2b10962ffa/raw/218b07739f6c146ec4ff15ec78657adc26455c95/data.txt"
raw <- read.table(gist_raw) 

col <- seq(1, nrow(raw), by = 3)
data.frame(col1 = raw[col,], col2 = raw[col + 1,], col3 = raw[col + 2,])

This gives you:

     col1  col2  col3
1 2017-02 57,25 10,50
2 2017-01 56,34 11,73
3 2016-12 58,98  8,74
4 2016-11 60,35  7,51
5 2016-10 60,77  8,29
6 2016-09 58,71  8,51
...

The parsing of the columns i leave to you.

Upvotes: 2

Related Questions