url <- "https://www.booksamillion.com/search?id=7523317361322&query=&filter=product_type%3Abooks"
first_page <- read_html(url)
# Read Title
Title <- html_nodes(first_page,'.title') %>% html_text() %>% str_trim() %>% unlist()
# Read Author
Author <- html_nodes(first_page,'.list') %>% html_nodes('.byline') %>% html_text() %>% str_trim() %>% unlist()
finaldf <- data.frame(title = Title,Auth = Author)
#...... separate ...... Author to Authors and ISBN
finaldf <- separate(finaldf,Auth,c("Author","ISBN"),sep = "ISBN")
#...... separate ...... ISBN to REL_Date and ISBN , as they are separated by "/"
finaldf <- separate(finaldf,ISBN,c("ISBN","REL_Date"),sep = "\\/")
#...... separate ......Author to Author1 and Author2 , as they are separated by ","
finaldf <- separate(finaldf,Author,c("Author1","Author2"),sep = ",")
## Warning: Expected 2 pieces. Additional pieces discarded in 2 rows [14, 19].
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 11 rows [1,
## 2, 3, 5, 6, 7, 9, 10, 11, 15, 17].
#.......trimws.......
finaldf$Author1 <- trimws(str_sub(finaldf$Author1,3,-1L))
finaldf$Author2 <- trimws(finaldf$Author2)
#.......Write CSV File .....
write.csv(finaldf,"book.csv")
# Reading Book xml from local directory
readBookXML <- read_lines("book.xml")
print(readBookXML)
## [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
## [2] "<root>"
## [3] " <book>"
## [4] " <element>"
## [5] " <Author1>Sarah J Maas </Author1>"
## [6] " <Author2 />"
## [7] " <ISBN>9.78155E+12</ISBN>"
## [8] " <REL_Date> May 2018</REL_Date>"
## [9] " <id>1</id>"
## [10] " <title>A Court of Frost and Starlight BAM Exclusive </title>"
## [11] " </element>"
## [12] " <element>"
## [13] " <Author1>Sarah J Maas </Author1>"
## [14] " <Author2 />"
## [15] " <ISBN>9.78155E+12</ISBN>"
## [16] " <REL_Date> May 2018</REL_Date>"
## [17] " <id>2</id>"
## [18] " <title>A Cou#$rt of Frost and Starlight BAM Exclusive </title>"
## [19] " </element>"
## [20] " <element>"
## [21] " <Author1>Sarah J Maas </Author1>"
## [22] " <Author2 />"
## [23] " <ISBN>9.78155E+12</ISBN>"
## [24] " <REL_Date> May 2018</REL_Date>"
## [25] " <id>3</id>"
## [26] " <title>A Court of Frdon't ost and Starlight BAM Exclusive </title>"
## [27] " </element>"
## [28] " </book>"
## [29] "</root>"
prefix.xml <- "<?xml version='1.0' encoding='UTF-8'?><root>
<element>
<title> 'MS DS Work'</title>
<author> 'Rajwant Mishra'</author>
</element>
</root>"
# DUMMY DATA FRAME
df <- tibble(title= finaldf$title,Author1 = finaldf$Author1,Author2 = finaldf$Author2,ISBN = finaldf$ISBN,REL_Date = finaldf$REL_Date)
# BUILD XML TREE
doc = xmlTreeParse(prefix.xml, useInternalNodes = T) # PARSE STRING
root = xmlRoot(doc) # FIND ROOT
bookNode = newXMLNode("book", parent=root) # ADD TO ROOT
xmlAttrs(bookNode) = c(type = "web") # ADD ATTRIBUTE
# pagesNode = newXMLNode("Element", parent=bookNode) # ADD TO REPORT
for (i in 1:nrow(df)){
eleNode = newXMLNode("Element", parent=bookNode) # ADD PAGE FOR EACH RECORD
xmlAttrs(eleNode) = c(ID = i)
# for (j in 1:ncol(df)){
newXMLNode("title", df$title[i], parent=eleNode) # ADD COL/ROW VALUE
newXMLNode("author1", df$Author1[i], parent=eleNode) # ADD COL/ROW VALUE
newXMLNode("author2", df$Author2[i], parent=eleNode) # ADD COL/ROW VALUE
newXMLNode("ISBN", df$ISBN[i], parent=eleNode) # ADD COL/ROW VALUE
newXMLNode("REL_Date", df$REL_Date[i], parent=eleNode) # ADD COL/ROW VALUE
# }
}
# VIEW XML
print(doc)
## <?xml version="1.0" encoding="UTF-8"?>
## <root>
## <element>
## <title> 'MS DS Work'</title>
## <author> 'Rajwant Mishra'</author>
## </element>
## <book type="web">
## <Element ID="1">
## <title>A Court of Frost and Starlight BAM Exclusive</title>
## <author1>Sarah J Maas</author1>
## <author2>NA</author2>
## <ISBN> 9781547600380 </ISBN>
## <REL_Date> May 2018</REL_Date>
## </Element>
## <Element ID="2">
## <title>Whiskey in a Teacup - Autographed Copy (Hardcover)</title>
## <author1>Reese Witherspoon</author1>
## <author2>NA</author2>
## <ISBN> 9781982110185 </ISBN>
## <REL_Date> September 2018</REL_Date>
## </Element>
## <Element ID="3">
## <title>In Pieces - Autographed Copy</title>
## <author1>Sally Field</author1>
## <author2>NA</author2>
## <ISBN> 9781538764299 </ISBN>
## <REL_Date> September 2018</REL_Date>
## </Element>
## <Element ID="4">
## <title>The 18th Abduction (Hardcover)</title>
## <author1>James Patterson</author1>
## <author2>Maxine Paetro</author2>
## <ISBN> 9780316420266 </ISBN>
## <REL_Date> April 2019</REL_Date>
## </Element>
## <Element ID="5">
## <title>Redemption (Hardcover)</title>
## <author1>David Baldacci</author1>
## <author2>NA</author2>
## <ISBN> 9781538761410 </ISBN>
## <REL_Date> April 2019</REL_Date>
## </Element>
## <Element ID="6">
## <title>BAM Exclusive Kingdom of Ash</title>
## <author1>Sarah J. Maas</author1>
## <author2>NA</author2>
## <ISBN> 9781547600427 </ISBN>
## <REL_Date> October 2018</REL_Date>
## </Element>
## <Element ID="7">
## <title>A Life Worth Living : What I Learned Along the Way (Paperback)</title>
## <author1>Chuck Reinhold</author1>
## <author2>NA</author2>
## <ISBN> 9781642791297 </ISBN>
## <REL_Date> August 2018</REL_Date>
## </Element>
## <Element ID="8">
## <title>The Umbrella Academy Volume 3 : Hotel Oblivion (Paperback)</title>
## <author1>Gerard Way</author1>
## <author2>Gabriel Ba</author2>
## <ISBN> 9781506711423 </ISBN>
## <REL_Date> August 2019</REL_Date>
## </Element>
## <Element ID="9">
## <title>Run Away (Hardcover)</title>
## <author1>Harlan Coben</author1>
## <author2>NA</author2>
## <ISBN> 9781538748466 </ISBN>
## <REL_Date> March 2019</REL_Date>
## </Element>
## <Element ID="10">
## <title>Neon Prey (Hardcover)</title>
## <author1>John Sandford</author1>
## <author2>NA</author2>
## <ISBN> 9780525536581 </ISBN>
## <REL_Date> April 2019</REL_Date>
## </Element>
## <Element ID="11">
## <title>The Mister (Paperback)</title>
## <author1>E L James</author1>
## <author2>NA</author2>
## <ISBN> 9781984898326 </ISBN>
## <REL_Date> April 2019</REL_Date>
## </Element>
## <Element ID="12">
## <title>Celtic Empire (Hardcover)</title>
## <author1>Clive Cussler</author1>
## <author2>Dirk Cussler</author2>
## <ISBN> 9780735218994 </ISBN>
## <REL_Date> March 2019</REL_Date>
## </Element>
## <Element ID="13">
## <title>The Cornwalls Are Gone (Hardcover)</title>
## <author1>James Patterson</author1>
## <author2>Brendan DuBois</author2>
## <ISBN> 9780316485555 </ISBN>
## <REL_Date> March 2019</REL_Date>
## </Element>
## <Element ID="14">
## <title>The Adventure Zone : Murder on the Rockport Limited! (Paperback)</title>
## <author1>Clint McElroy</author1>
## <author2>Griffin McElroy</author2>
## <ISBN> 9781250153715 </ISBN>
## <REL_Date> July 2019</REL_Date>
## </Element>
## <Element ID="15">
## <title>Walt Disney's Ultimate Inventor : The Genius of Ub Iwerks (Hardcover)</title>
## <author1>Don Iwerks</author1>
## <author2>NA</author2>
## <ISBN> 9781484743379 </ISBN>
## <REL_Date> October 2019</REL_Date>
## </Element>
## <Element ID="16">
## <title>The Disney Monorail : Imagineering the Highway in the Sky (Hardcover)</title>
## <author1>Jeff Kurtti</author1>
## <author2>Vanessa Hunt</author2>
## <ISBN> 9781484737675 </ISBN>
## <REL_Date> October 2019</REL_Date>
## </Element>
## <Element ID="17">
## <title>Wild Card (Hardcover)</title>
## <author1>Stuart Woods</author1>
## <author2>NA</author2>
## <ISBN> 9780735219281 </ISBN>
## <REL_Date> March 2019</REL_Date>
## </Element>
## <Element ID="18">
## <title>The Red Scrolls of Magic (Hardcover)</title>
## <author1>Cassandra Clare</author1>
## <author2>Wesley Chu</author2>
## <ISBN> 9781481495080 </ISBN>
## <REL_Date> April 2019</REL_Date>
## </Element>
## <Element ID="19">
## <title>The Hidden Power of F*cking Up (Hardcover)</title>
## <author1>The Try Guys</author1>
## <author2>Keith Habersberger</author2>
## <ISBN> 9780062879615 </ISBN>
## <REL_Date> June 2019</REL_Date>
## </Element>
## </book>
## </root>
##
# Local Sample JOSN File .
readBookJSON <- read_lines("book.json")
print(readBookJSON)
## [1] "{"
## [2] " \"book\":["
## [3] " { "
## [4] " \"id\" : 1 ,"
## [5] " \"title\" : \"A Court of Frost and Starlight BAM Exclusive \","
## [6] " \"Author1\": \"Sarah J Maas \","
## [7] " \"Author2\": \"\","
## [8] " \"ISBN\": \"9.78155E+12\","
## [9] " \"REL_Date\": \" May 2018\""
## [10] " },"
## [11] " { "
## [12] " \"id\" : 1 ,"
## [13] " \"title\" : \"A Court of Frost and Starlight BAM Exclusive \","
## [14] " \"Author1\": \"Sarah J Maas \","
## [15] " \"Author2\": \"\","
## [16] " \"ISBN\": \"9.78155E+12\","
## [17] " \"REL_Date\": \" May 2018\""
## [18] " },"
## [19] ""
## [20] " { "
## [21] " \"id\" : 1 ,"
## [22] " \"title\" : \"A Court of Frost and Starlight BAM Exclusive \","
## [23] " \"Author1\": \"Sarah J Maas \","
## [24] " \"Author2\": \"\","
## [25] " \"ISBN\": \"9.78155E+12\","
## [26] " \"REL_Date\": \" May 2018\""
## [27] " } "
## [28] ""
## [29] " ],"
## [30] " \"Comic\":["
## [31] " { "
## [32] " \"id\" : 1 ,"
## [33] " \"title\" : \"A Court of Frost and Starlight BAM Exclusive \","
## [34] " \"Author1\": \"Sarah J Maas \","
## [35] " \"Author2\": \"\","
## [36] " \"ISBN\": \"9.78155E+12\","
## [37] " \"REL_Date\": \" May 2018\""
## [38] " },"
## [39] " { "
## [40] " \"id\" : 1 ,"
## [41] " \"title\" : \"A Court of Frost and Starlight BAM Exclusive \","
## [42] " \"Author1\": \"Sarah J Maas \","
## [43] " \"Author2\": \"\","
## [44] " \"ISBN\": \"9.78155E+12\","
## [45] " \"REL_Date\": \" May 2018\""
## [46] " },"
## [47] ""
## [48] " { "
## [49] " \"id\" : 1 ,"
## [50] " \"title\" : \"A Court of Frost and Starlight BAM Exclusive \","
## [51] " \"Author1\": \"Sarah J Maas \","
## [52] " \"Author2\": \"\","
## [53] " \"ISBN\": \"9.78155E+12\","
## [54] " \"REL_Date\": \" May 2018\""
## [55] " } "
## [56] ""
## [57] " ]"
## [58] "}"
## [59] ""
jsonlite::toJSON(df)
## [{"title":"A Court of Frost and Starlight BAM Exclusive","Author1":"Sarah J Maas","ISBN":" 9781547600380 ","REL_Date":" May 2018"},{"title":"Whiskey in a Teacup - Autographed Copy (Hardcover)","Author1":"Reese Witherspoon","ISBN":" 9781982110185 ","REL_Date":" September 2018"},{"title":"In Pieces - Autographed Copy","Author1":"Sally Field","ISBN":" 9781538764299 ","REL_Date":" September 2018"},{"title":"The 18th Abduction (Hardcover)","Author1":"James Patterson","Author2":"Maxine Paetro","ISBN":" 9780316420266 ","REL_Date":" April 2019"},{"title":"Redemption (Hardcover)","Author1":"David Baldacci","ISBN":" 9781538761410 ","REL_Date":" April 2019"},{"title":"BAM Exclusive Kingdom of Ash","Author1":"Sarah J. Maas","ISBN":" 9781547600427 ","REL_Date":" October 2018"},{"title":"A Life Worth Living : What I Learned Along the Way (Paperback)","Author1":"Chuck Reinhold","ISBN":" 9781642791297 ","REL_Date":" August 2018"},{"title":"The Umbrella Academy Volume 3 : Hotel Oblivion (Paperback)","Author1":"Gerard Way","Author2":"Gabriel Ba","ISBN":" 9781506711423 ","REL_Date":" August 2019"},{"title":"Run Away (Hardcover)","Author1":"Harlan Coben","ISBN":" 9781538748466 ","REL_Date":" March 2019"},{"title":"Neon Prey (Hardcover)","Author1":"John Sandford","ISBN":" 9780525536581 ","REL_Date":" April 2019"},{"title":"The Mister (Paperback)","Author1":"E L James","ISBN":" 9781984898326 ","REL_Date":" April 2019"},{"title":"Celtic Empire (Hardcover)","Author1":"Clive Cussler","Author2":"Dirk Cussler","ISBN":" 9780735218994 ","REL_Date":" March 2019"},{"title":"The Cornwalls Are Gone (Hardcover)","Author1":"James Patterson","Author2":"Brendan DuBois","ISBN":" 9780316485555 ","REL_Date":" March 2019"},{"title":"The Adventure Zone : Murder on the Rockport Limited! (Paperback)","Author1":"Clint McElroy","Author2":"Griffin McElroy","ISBN":" 9781250153715 ","REL_Date":" July 2019"},{"title":"Walt Disney's Ultimate Inventor : The Genius of Ub Iwerks (Hardcover)","Author1":"Don Iwerks","ISBN":" 9781484743379 ","REL_Date":" October 2019"},{"title":"The Disney Monorail : Imagineering the Highway in the Sky (Hardcover)","Author1":"Jeff Kurtti","Author2":"Vanessa Hunt","ISBN":" 9781484737675 ","REL_Date":" October 2019"},{"title":"Wild Card (Hardcover)","Author1":"Stuart Woods","ISBN":" 9780735219281 ","REL_Date":" March 2019"},{"title":"The Red Scrolls of Magic (Hardcover)","Author1":"Cassandra Clare","Author2":"Wesley Chu","ISBN":" 9781481495080 ","REL_Date":" April 2019"},{"title":"The Hidden Power of F*cking Up (Hardcover)","Author1":"The Try Guys","Author2":"Keith Habersberger","ISBN":" 9780062879615 ","REL_Date":" June 2019"}]
htmltools::includeHTML("book.html")
| title | author | author2 | ISBN | REL_Date | |
|---|---|---|---|---|---|
| 1 | A Court of Frost and Starlight BAM Exclusive | Sarah J Maas | NA | 9781547600380 | May 2018 |
| 2 | Whiskey in a Teacup - Autographed Copy (Hardcover) | Reese Witherspoon | NA | 9781982110185 | September 2018 |
| 3 | In Pieces - Autographed Copy | Sally Field | NA | 9781538764299 | September 2018 |
| 4 | The 18th Abduction (Hardcover) | James Patterson | Maxine Paetro | 9780316420266 | April 2019 |
| 5 | Redemption (Hardcover) | David Baldacci | NA | 9781538761410 | April 2019 |
| 6 | BAM Exclusive Kingdom of Ash | Sarah J. Maas | NA | 9781547600427 | October 2018 |
| 1 | A Court of Frost and Starlight BAM Exclusive | Sarah J Maas | NA | 9781547600380 | May 2018 |
| 2 | Whiskey in a Teacup - Autographed Copy (Hardcover) | Reese Witherspoon | NA | 9781982110185 | September 2018 |
| 3 | In Pieces - Autographed Copy | Sally Field | NA | 9781538764299 | September 2018 |
| 4 | The 18th Abduction (Hardcover) | James Patterson | Maxine Paetro | 9780316420266 | April 2019 |
| 5 | Redemption (Hardcover) | David Baldacci | NA | 9781538761410 | April 2019 |
| 6 | BAM Exclusive Kingdom of Ash | Sarah J. Maas | NA | 9781547600427 | October 2018 |
XMLurl <- "https://raw.githubusercontent.com/Rajwantmishra/msds/master/607/week7/bookRXml.xml"
readBookXML <- read_xml("bookRXml.xml")
readBookXML <- read_xml(XMLurl)
print(readBookXML)
## {xml_document}
## <root>
## [1] <element>\n <title> 'MS DS Work'</title>\n <author> 'Rajwant Mishr ...
## [2] <book type="web">\n <Element ID="1">\n <title>A Court of Frost a ...
xbook <- xml_children(readBookXML)
xbook.element <- xml_children(xbook[2])
xml_children(xbook.element[1])
## {xml_nodeset (5)}
## [1] <title>A Court of Frost and Starlight BAM Exclusive</title>
## [2] <author1>Sarah J Maas</author1>
## [3] <author2>NA</author2>
## [4] <ISBN> 9781547600380 </ISBN>
## [5] <REL_Date> May 2018</REL_Date>
xml_path(xbook)
## [1] "/root/element" "/root/book"
# -----
class(xml_find_all(readBookXML, ".//title"))
## [1] "xml_nodeset"
xml_title <- xml_find_all(xbook.element, ".//title")
xml_author1 <- xml_text(xml_find_all(readBookXML, ".//author1"))
xml_author2 <-xml_text(xml_find_all(readBookXML, ".//author2"))
xml_ISBN <- xml_text(xml_find_all(readBookXML, ".//ISBN"))
xml_REL_Date <-xml_text(xml_find_all(readBookXML, ".//REL_Date"))
xml_titleAll <- xml_text(xml_find_all(readBookXML, ".//title"))
ldply(xml_text(xml_children(xbook.element[1])))
x <- read_xml("<root id='1'><child id ='a' /><child id='b' d='b'/></root>")
xml_attr(x, "id")
## [1] "1"
xml_attr(x, "apple")
## [1] NA
xml_attrs(xbook.element,"ID")
## [[1]]
## ID
## "1"
##
## [[2]]
## ID
## "2"
##
## [[3]]
## ID
## "3"
##
## [[4]]
## ID
## "4"
##
## [[5]]
## ID
## "5"
##
## [[6]]
## ID
## "6"
##
## [[7]]
## ID
## "7"
##
## [[8]]
## ID
## "8"
##
## [[9]]
## ID
## "9"
##
## [[10]]
## ID
## "10"
##
## [[11]]
## ID
## "11"
##
## [[12]]
## ID
## "12"
##
## [[13]]
## ID
## "13"
##
## [[14]]
## ID
## "14"
##
## [[15]]
## ID
## "15"
##
## [[16]]
## ID
## "16"
##
## [[17]]
## ID
## "17"
##
## [[18]]
## ID
## "18"
##
## [[19]]
## ID
## "19"
xml_children(xml_children(xbook[2]))
## {xml_nodeset (95)}
## [1] <title>A Court of Frost and Starlight BAM Exclusive</title>
## [2] <author1>Sarah J Maas</author1>
## [3] <author2>NA</author2>
## [4] <ISBN> 9781547600380 </ISBN>
## [5] <REL_Date> May 2018</REL_Date>
## [6] <title>Whiskey in a Teacup - Autographed Copy (Hardcover)</title>
## [7] <author1>Reese Witherspoon</author1>
## [8] <author2>NA</author2>
## [9] <ISBN> 9781982110185 </ISBN>
## [10] <REL_Date> September 2018</REL_Date>
## [11] <title>In Pieces - Autographed Copy</title>
## [12] <author1>Sally Field</author1>
## [13] <author2>NA</author2>
## [14] <ISBN> 9781538764299 </ISBN>
## [15] <REL_Date> September 2018</REL_Date>
## [16] <title>The 18th Abduction (Hardcover)</title>
## [17] <author1>James Patterson</author1>
## [18] <author2>Maxine Paetro</author2>
## [19] <ISBN> 9780316420266 </ISBN>
## [20] <REL_Date> April 2019</REL_Date>
## ...
xml_find_first(xbook.element, ".//title")
## {xml_nodeset (19)}
## [1] <title>A Court of Frost and Starlight BAM Exclusive</title>
## [2] <title>Whiskey in a Teacup - Autographed Copy (Hardcover)</title>
## [3] <title>In Pieces - Autographed Copy</title>
## [4] <title>The 18th Abduction (Hardcover)</title>
## [5] <title>Redemption (Hardcover)</title>
## [6] <title>BAM Exclusive Kingdom of Ash</title>
## [7] <title>A Life Worth Living : What I Learned Along the Way (Paperba ...
## [8] <title>The Umbrella Academy Volume 3 : Hotel Oblivion (Paperback)< ...
## [9] <title>Run Away (Hardcover)</title>
## [10] <title>Neon Prey (Hardcover)</title>
## [11] <title>The Mister (Paperback)</title>
## [12] <title>Celtic Empire (Hardcover)</title>
## [13] <title>The First Lady (Paperback)</title>
## [14] <title>The Cornwalls Are Gone (Hardcover)</title>
## [15] <title>The Adventure Zone : Murder on the Rockport Limited! (Paper ...
## [16] <title>Walt Disney's Ultimate Inventor : The Genius of Ub Iwerks ( ...
## [17] <title>The Disney Monorail : Imagineering the Highway in the Sky ( ...
## [18] <title>The Hidden Power of F*cking Up (Hardcover)</title>
## [19] <title>The Red Scrolls of Magic (Hardcover)</title>
xml_text(xml_find_all(xbook.element, ".//title"))
## [1] "A Court of Frost and Starlight BAM Exclusive"
## [2] "Whiskey in a Teacup - Autographed Copy (Hardcover)"
## [3] "In Pieces - Autographed Copy"
## [4] "The 18th Abduction (Hardcover)"
## [5] "Redemption (Hardcover)"
## [6] "BAM Exclusive Kingdom of Ash"
## [7] "A Life Worth Living : What I Learned Along the Way (Paperback)"
## [8] "The Umbrella Academy Volume 3 : Hotel Oblivion (Paperback)"
## [9] "Run Away (Hardcover)"
## [10] "Neon Prey (Hardcover)"
## [11] "The Mister (Paperback)"
## [12] "Celtic Empire (Hardcover)"
## [13] "The First Lady (Paperback)"
## [14] "The Cornwalls Are Gone (Hardcover)"
## [15] "The Adventure Zone : Murder on the Rockport Limited! (Paperback)"
## [16] "Walt Disney's Ultimate Inventor : The Genius of Ub Iwerks (Hardcover)"
## [17] "The Disney Monorail : Imagineering the Highway in the Sky (Hardcover)"
## [18] "The Hidden Power of F*cking Up (Hardcover)"
## [19] "The Red Scrolls of Magic (Hardcover)"
XML_Book <- tibble( title = unlist(xml_text(xml_title)),
author = unlist(xml_author1),
author2 = unlist(xml_author2),
ISBN = unlist(xml_ISBN),
REL_Date = unlist(xml_REL_Date)
)
ldply(xml_text(xml_title))
datatable(XML_Book)
jsonURL <- "https://raw.githubusercontent.com/Rajwantmishra/msds/master/607/week7/bookR.json"
readbookJOSN <- read_file(jsonURL)
jsonlite::fromJSON(readbookJOSN)
#LOCAL READ
readbookJOSN <- read_file("book.json")
jsonlite::fromJSON(readbookJOSN)
## $book
## id title Author1 Author2
## 1 1 A Court of Frost and Starlight BAM Exclusive Sarah J Maas
## 2 1 A Court of Frost and Starlight BAM Exclusive Sarah J Maas
## 3 1 A Court of Frost and Starlight BAM Exclusive Sarah J Maas
## ISBN REL_Date
## 1 9.78155E+12 May 2018
## 2 9.78155E+12 May 2018
## 3 9.78155E+12 May 2018
##
## $Comic
## id title Author1 Author2
## 1 1 A Court of Frost and Starlight BAM Exclusive Sarah J Maas
## 2 1 A Court of Frost and Starlight BAM Exclusive Sarah J Maas
## 3 1 A Court of Frost and Starlight BAM Exclusive Sarah J Maas
## ISBN REL_Date
## 1 9.78155E+12 May 2018
## 2 9.78155E+12 May 2018
## 3 9.78155E+12 May 2018
bookHTML <- read_html("book.html")
# ------------------Method 1
bookHTML1 <- read_html("book.html")
tbls_ls <- bookHTML1 %>%
html_nodes("table") %>%
.[1] %>%
html_table(fill = TRUE)
str(tbls_ls)
## List of 1
## $ :'data.frame': 12 obs. of 6 variables:
## ..$ : int [1:12] 1 2 3 4 5 6 1 2 3 4 ...
## ..$ title : chr [1:12] "A Court of Frost and Starlight BAM Exclusive" "Whiskey in a Teacup - Autographed Copy (Hardcover)" "In Pieces - Autographed Copy" "The 18th Abduction (Hardcover)" ...
## ..$ author : chr [1:12] "Sarah J Maas" "Reese Witherspoon" "Sally Field" "James Patterson" ...
## ..$ author2 : chr [1:12] NA NA NA "Maxine Paetro" ...
## ..$ ISBN : num [1:12] 9.78e+12 9.78e+12 9.78e+12 9.78e+12 9.78e+12 ...
## ..$ REL_Date: chr [1:12] "May 2018" "September 2018" "September 2018" "April 2019" ...
# ------------------Method 2
readHTMLTable("book.html")[[1]]
fs$download('book.csv','bookMONGO.csv')
bookMongoCSV <- read_csv("bookMONGO.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_double(),
## title = col_character(),
## Author1 = col_character(),
## Author2 = col_character(),
## ISBN = col_double(),
## REL_Date = col_character()
## )
datatable(bookMongoCSV)