La funzione read_html
genera un xml_document che mi piacerebbe salvare e in seguito il carico per analizzarlo.Impossibile salvare - carico xml_document generata da rvest in R
Il problema è che dopo aver caricato il xml_document non c'è html all'interno di esso.
library(rvest)
library(magrittr)
doc <- read_html("http://www.example.com/")
doc %>% html_node("h1") %>% html_text
ottengo: [1] "Example Domain"
Ma quando salvo prima l'oggetto xml_document doc
e inserirla nuovamente sembra che tutto è stato cancellato.
save(doc, file=paste0(getwd(), "/example.RData"))
rm(doc)
load(file=paste0(getwd(), "/example.RData"))
doc %>% html_node("h1") %>% html_text
ottengo: Error: No matches
O quando ho eseguito doc
ottengo: {xml_document}
un xml_document vuota.
È anche il caso che quando eseguo il doc
, dopo averlo caricato, ricevo un messaggio che RStudio ha smesso di funzionare.
ho provato su due diverse macchine Windows, ha ottenuto lo stesso problema.
sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] magrittr_1.5 rvest_0.3.1.9000 xml2_0.1.2
loaded via a namespace (and not attached):
[1] httr_1.1.0 R6_2.1.2 tools_3.3.0 Rcpp_0.12.5
Ho incontrato lo stesso errore. [Ho aperto un problema su Github] (https://github.com/hadley/rvest/issues/181). – Deleet