Skip to content

Instantly share code, notes, and snippets.

@bearloga
Created November 9, 2017 18:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearloga/5a53c6bd7c1c05ef0d6eb2e7eac57134 to your computer and use it in GitHub Desktop.
Save bearloga/5a53c6bd7c1c05ef0d6eb2e7eac57134 to your computer and use it in GitHub Desktop.
Some code for converting an HTML description list into an R data.frame that can then be exported as a CSV.
library(rvest)
x <- "<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>"
y <- read_html(x)
df <- data.frame(
dt = html_text(html_nodes(y, "dt")),
dd = html_text(html_nodes(y, "dd")),
stringsAsFactors = FALSE
)
df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment