Created
November 9, 2017 18:15
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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