Search code examples
rwebscreen-scrapingrselenium

RSelenium - Web Scraping - Zepp - Personal Soccer Data


I have a soccer app which tracks my data while I play - however I want an automated way of collecting this data for myself.

Here is an example of the page I am trying to scrape, though I don't seem to be making any progress with RSelenium.

I'm able to make initial contact, and obtain the title of the page, but can't seem to grab hold of anything beyond that.

library(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "127.0.0.1",
                      port = 4445L)
remDr$open(silent = TRUE)

remDr$navigate("http://sport.zepp.com/soccer/game?id=602f7c549c05de4254619ce2&uid=602dfa34286a8427b94ef43d")
remDr$getTitle()

I'd at least like to be able to track the "distance" metric of 3.18m, near the top of the page. Is anybody able to give me a working example of how I may do this? Eventually I'd like to be able to get the rest of the page as well.


Solution

  • Below a possible solution.

    library(RSelenium)
    driver <- rsDriver(browser=c("firefox"), port = 4445L)
    remote_driver <- driver[["client"]]
    
    remote_driver$navigate("http://sport.zepp.com/soccer/game?id=602f7c549c05de4254619ce2&uid=602dfa34286a8427b94ef43d")
    DISTANCE<-remote_driver$findElement(using = 'css selector', value = 'div.ct-container:nth-child(1) > div:nth-child(2) > div:nth-child(2)')$getElementText()
    print(DISTANCE)
    [[1]]
    [1] "5125"
    
    KICKS<-remote_driver$findElement(using = 'css selector', value = '#SoccerGameApp > div > div:nth-child(2) > div:nth-child(2) > div > div:nth-child(2) > div > div.flt_r.ct-h-r')$getElementText()
    print(KICKS)
    [[1]]
    [1] "21"
    
    SPRINTS<-remote_driver$findElement(using = 'css selector', value = '#SoccerGameApp > div > div:nth-child(2) > div:nth-child(2) > div > div:nth-child(3) > div > div.flt_r.ct-h-r')$getElementText()
    print(SPRINTS)
    [[1]]
    [1] "17"