1

I am trying to download the share count from the left SumoMe plugin of this website http://www.r-bloggers.com/erum-2016-first-european-conference-for-the-programming-language-r/

I try to use R code based on rvest package

> library(rvest)
Loading required package: xml2
> url <- 'http://www.r-bloggers.com/erum-2016-first-european-conference-for-the-programming-language-r/'
> read_html(url) %>%
+   html_nodes('.wpusb-counts span')
{xml_nodeset (1)}
[1] <span data-element="total-share"></span>

But have received empty response. The page looks like to start with 0 share-count and then it updates after a few second after you spend time on that website. Can someone could suggest any possible solution to that or advice any package? Is RSelenium a good package for that? I haven't used it before.

Stedy
  • 7,359
  • 14
  • 57
  • 77
Marcin
  • 7,834
  • 8
  • 52
  • 99

1 Answers1

2

It looks like that value is loaded asynchronously by javascript so yes, RSelenium may be your best bet. I ended up using the xpath selector in Firebug to pass that parameter to browser$findElement

library(RSelenium)

browser <- remoteDriver()
browser$open()
browser$navigate('http://www.r-bloggers.com/erum-2016-first-european-conference-for-the-programming-language-r/')
value <- browser$findElement(using = 'xpath', '/html/body/div[5]/div/div[1]/div/span')
print(value$getElementText())

[[1]]
[1] "7"
Stedy
  • 7,359
  • 14
  • 57
  • 77
  • Simple, short and amazing. R is powerful! Did You Have to use startServer function for that snippet? – Marcin Jul 10 '16 at 18:14
  • 1
    I did not, but am also running ubuntu 14.04 and it worked without that command but may be a different story on another OS. – Stedy Jul 10 '16 at 18:25
  • I get `> library(RSelenium) Loading required package: RCurl Loading required package: bitops Loading required package: RJSONIO Loading required package: XML Attaching package: ‘XML’ The following object is masked from ‘package:rvest’: xml > > browser <- remoteDriver() > browser$open() [1] "Connecting to remote server" Undefined error in RCurl call. Error in queryRD(paste0(serverURL, "/session"), "POST", qdata = toJSON(serverOpts)) :` – Marcin Jul 13 '16 at 11:33