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.

4

1 回答 1

2

看起来该值是由 javascript 异步加载的,所以是的,RSelenium可能是您最好的选择。我最终在 Firebug 中使用 xpath 选择器将该参数传递给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"
于 2016-07-09T04:16:45.677 回答