How to convert an HTML R object to character?

随声附和 提交于 2019-12-06 13:36:58

To save directly to a text file:

capture.output(page, file="file.html")

To store as a string:

htmltxt <- paste(capture.output(page, file=NULL), collapse="\n")

Or, you can just use saveXML from the XML package to handle the HTML/XML object directly without other machinations.

library(rvest)
library(XML)

pg <- html("http://dds.ec/")
saveXML(pg, "output.html")

Replace as.character(page) with as(page, "character")

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!