data analysis & visualization

우분투에 도커 설치


sudo curl -fsSL https://get.docker.com/ | sudo sh


docker pull selenium/standalone-chrome



도커에서 셀레늄을 4444~4445 port 열기


sudo docker run -p 4445:4444 selenium/standalone-chrome




이제 R-studio 서버에 접속



library(RSelenium)

library(stringr)

remDr<-remoteDriver(port=4445L,browserName='chrome')

remDr$open()

name=c('대구대','영남대','계명대')

geo_code=function(name,n=3){

  url='https://www.google.com/maps'

  remDr$navigate(url)

  search=NULL

  while(length(search)==0){

    assign('search',remDr$findElement(using='css selector',value='input#searchboxinput.tactile-searchbox-input'))

  }

  data=NULL

  for(i in 1:length(name)){

    search$clearElement()

    search$sendKeysToElement(list(name[i],key='enter'))

    Sys.sleep(n)

lonlat=as.numeric(str_split(substr(remDr$getCurrentUrl()[[1]],

regexpr('@',remDr$getCurrentUrl()[[1]])+1,regexpr(',[0-9]+z',remDr$getCurrentUrl()[[1]])-1),',')[[1]])

    data=rbind(data,data.frame(name=name[i],lat=lonlat[1],lon=lonlat[2]))

  }

  return(data)

}

a=geo_code(name)

remDr$close()




끗!