-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathassignment7_607.Rmd
More file actions
55 lines (43 loc) · 1.32 KB
/
assignment7_607.Rmd
File metadata and controls
55 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
title: "Assignment7_607"
author: "Alvaro Bueno"
date: "10/13/2017"
output:
html_document: default
pdf_document: default
---
```{r setup, include=FALSE}
library(RCurl)
library(XML)
library(jsonlite)
library(knitr)
```
```{r html_table}
html <- url('https://raw.githubusercontent.com/delagroove/dataScience/master/books.html')
webpage <- readLines(html)
htmltable <- readHTMLTable(webpage)
htmldata <- htmlParse(webpage, encoding="UTF-8")
result_href <- xpathSApply(htmldata, "//*/table/tr/td/a", xmlGetAttr, 'href')
htmltable <- as.data.frame(htmltable)
htmltable$sourceUrl <- result_href
```
```{r xml_table}
xData <- getURL('https://raw.githubusercontent.com/delagroove/dataScience/master/books.xml')
doc <- xmlParse(xData)
xmltable <- xmlToDataFrame(
getNodeSet(doc, "//book")
)
result_href <- xpathSApply(doc, "//*/book/Source", xmlGetAttr, 'url')
xmltable$sourceUrl <- result_href
```
```{r json_table}
jData <- getURL('https://raw.githubusercontent.com/delagroove/dataScience/master/books.json')
jsontable <- fromJSON(jData)
```
The tables are not exactly identical, but they can be if we rename the columns in the HTML table.
```{r rename_cols}
names(htmltable) <- c('Name','Author', 'Description','Published Date', 'Editorial', 'Format', 'NumPages', 'Source','SourceUrl')
kable(htmltable)
kable(xmltable)
kable(jsontable)
```