library(stringr)
library(RCurl)
## Loading required package: bitops
library(RJSONIO)
library(jsonlite)
##
## Attaching package: 'jsonlite'
## The following objects are masked from 'package:RJSONIO':
##
## fromJSON, toJSON
library(XML)
library(knitr)
## Warning: package 'knitr' was built under R version 3.3.3
#library(RTidyHTML)
Parse HTML from Web and convert to Data Frame
booksContent <- getURL("https://raw.githubusercontent.com/jmehta753/MSDA_JM/master/DATA607/Week7/books.html")
books <- htmlParse(booksContent, useInternalNodes = TRUE)
child <- xmlChildren(xmlRoot(books))
child <- xmlChildren(child$body)
table <- xmlChildren(child$table)
HTMLDF <- readHTMLTable(child$table)
kable(HTMLDF)
| Id |
Title |
Authors |
Year |
Genres |
Movie Adaptation |
| 1 |
The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography |
Simon Singh |
2000 |
Cryptography, Linguistics, History |
 |
| 2 |
Alan Turing: The Enigma |
Andrew Hodges, Douglas Hofstadter |
1985 |
History, Mathematics, Technology |
The Imitation Game |
| 3 |
Hidden Figures: The Story of the African-American Women Who Helped Win the Space Race |
Margot Lee Shetterly |
2016 |
History, African-American, Technology |
Hidden Figures |
Parse JSON from Web and convert to Data Frame
booksJson <- getURL("https://raw.githubusercontent.com/jmehta753/MSDA_JM/master/DATA607/Week7/books.json")
booksJsonDF<-fromJSON(booksJson)
kable(booksJsonDF)
| 1 |
The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography |
Simon Singh |
2000 |
Cryptography, Linguistics, History |
NA |
| 2 |
Alan Turing: The Enigma |
Andrew Hodges, Douglas Hofstadter |
1985 |
History, Mathematics, Technology |
The Imitation Game |
| 3 |
Hidden Figures: The Story of the African-American Women Who Helped Win the Space Race |
Margot Lee Shetterly |
2016 |
History, African-American, Technology |
Hidden Figures |
Parse XML from Web and convert to Data Frame
booksXml <- getURL("https://raw.githubusercontent.com/jmehta753/MSDA_JM/master/DATA607/Week7/books.xml")
booksXml1 <- xmlParse(booksXml)
booksXml1 <- xmlRoot(booksXml1)
booksXMLDF <- xmlSApply(booksXml1, function(x) xmlSApply(x, xmlValue))
booksXMLDF <- data.frame(t(booksXMLDF), row.names = NULL)
kable(booksXMLDF)
| 1 |
The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography |
Simon Singh |
2000 |
Cryptography, Linguistics, History |
|
| 2 |
Alan Turing: The Enigma |
Andrew Hodges, Douglas Hofstadter |
1985 |
History, Mathematics, Technology |
The Imitation Game |
| 3 |
Hidden Figures: The Story of the African-American Women Who Helped Win the Space Race |
Margot Lee Shetterly |
2016 |
History, African-American, Technology |
Hidden Figures |