Here's my reproducible example:
library(rvest)
page <- html("http://google.com")
class(page)
page
> as.character(page)
Error in as.vector(x, "character") :
cannot coerce type 'externalptr' to vector of type 'character'
How can I convert page from an html class to a character vector so I can store it somewhere?
The html functions like html_text or html_attr don't give me the whole source. I would like to store it so I can later re-load it with html().
Thanks.
Replace
as.character(page)
withas(page, "character")
Or, you can just use
saveXML
from theXML
package to handle the HTML/XML object directly without other machinations.To save directly to a text file:
To store as a string: