2016-03-31 7 views
1

Ich habe Rvest verwendet, um den Kommentar von einem Fußballspiel von ESPNFC.co.ra kratzen, aber ich kämpfe um die endgültige Ausgabe, die ich brauche.Rvest Turn Final String in mehrere Zeilen

library("rvest") 
library("xlsx") 
espnfc<-html("http://www.espnfc.co.uk/commentary/422421/commentary.html") 
    commentary<-espnfc %>% 
    html_nodes("#convo-window") %>% 
    html_text() 
commentary <- gsub ("\n", "", commentary) 
commentary <- gsub ("\r", "", commentary) 
commentary <- gsub ("\t", "", commentary) 

Die endgültige Ausgabe ist eine große Zeichenfolge, aber ich würde die Aktion von jeder Minute wie eine Zeile in einem Datenrahmen zu sein, zum Beispiel:

"90'Second Half ends, Liverpool 2, Sunderland 2." 
"90'Attempt blocked. Adam Johnson (Sunderland) right footed shot from outside the box is blocked. Assisted by Patrick van Aanholt." 
"90'Attempt missed. Jordon Ibe (Liverpool) right footed shot from outside the box is close, but misses to the left. Assisted by Mamadou Sakho." 
"90'Lucas Leiva (Liverpool) wins a free kick in the attacking half." 

Wie kann ich über diese gehen ?

Antwort

4

die CSS-Selektor wird Ihr Leben einfacher

espnfc<-html("http://www.espnfc.co.uk/commentary/422421/commentary.html") 
commentary<-espnfc %>% 
html_nodes(".comment p") %>% 
html_text() 

minute<-espnfc %>% 
html_nodes(".timestamp p") %>% 
html_text() 

df<-data.frame(minute=minute,commentary=commentary) 
machen