Google translate via web scraping r

前端 未结 1 1432
你的背包
你的背包 2021-01-16 08:55

I have a list of 1000 text in Russian language and want to convert it to English in R. I know there are some R packages for google translate but that requires API. And getti

1条回答
  •  再見小時候
    2021-01-16 09:22

    Here is a solution ,

    library(RCurl)
    library(XML)
    
    getParam = "Прием (осмотр, консультация) врача-инфекциониста первичный"
    translateFrom = "ru"
    translateTo = "en"
    
    search <- gsub(" ", "%20", getParam)
    
    URL <- paste("https://translate.google.pl/m?hl=",translateFrom,"&sl=",translateFrom,"&tl=",translateTo,"&ie=UTF-8&prev=_m&q=",search,sep="")
    
    page <- getURL(URL)
    
    tree <-htmlTreeParse(page)
    
    body <- tree$children$html$children$body 
    
    body_text <- body$children[[5]]$children[[1]]  
    
    print(body_text) 
    

    You can find more information about web parsing from this question.

    0 讨论(0)
提交回复
热议问题