library(RCurl)
library(XML)
library(jsonlite)
I create an HTML file and input the book’s information into the file. Then read the HTML with R.
html = getURLContent('https://raw.githubusercontent.com/Benson90/607Week7/main/Books.html')
html = readHTMLTable(html)
html = html[[1]]
html
## Title
## 1 Liftoff: Elon Musk and the Desperate Early Days That Launched SpaceX
## 2 Going There
## 3 Homeland Elegies
## Author Attributes
## 1 Eric Berger Fascinating, Successful
## 2 Katie Couric heartfelt, loved
## 3 Ayad Akhtar fiction, semi-autobiographical,political
I create a XML format file and input the book’s information. Then read the XML file with R.
xml = getURLContent("https://raw.githubusercontent.com/Benson90/607Week7/main/Books.xml")
xml = gsub("&", "&", xml)
xml = xmlParse(xml)
xml = xmlToDataFrame(xml)
xml
## title
## 1 Liftoff: Elon Musk and the Desperate Early Days That Launched SpaceX
## 2 Going There
## 3 Homeland Elegies
## author attributes
## 1 Eric Berger Fascinating, Successful
## 2 Katie Couric Heartfelt, Loved
## 3 Ayad Akhtar fiction, semi-autobiographical,political
I create a Json format file and input the book’s information. Then read the Json file with R.
json = getURLContent("https://raw.githubusercontent.com/Benson90/607Week7/main/books.json")
json = fromJSON(json)
json = as.data.frame(json)
json
## books.title
## 1 Liftoff: Elon Musk and the Desperate Early Days That Launched SpaceX
## 2 Going There
## 3 Homeland Elegies
## books.author books.attribute
## 1 Eric Berger Fascinating, Successful
## 2 Katie Couric Heartfelt, Loved
## 3 Ayad Akhtar fiction, semi-autobigraphical, political