<polite session> https://books.toscrape.com/
User-agent: EPPS6302 student; bjs170000@utdallas.edu
robots.txt: 1 rules are defined for 1 bots
Crawl delay: 5 sec
The path is scrapable for this user-agent
# A tibble: 20 × 4
title price rating stock
<chr> <chr> <chr> <chr>
1 A Light in the Attic £51.… star-… In s…
2 Tipping the Velvet £53.… star-… In s…
3 Soumission £50.… star-… In s…
4 Sharp Objects £47.… star-… In s…
5 Sapiens: A Brief History of Humankind £54.… star-… In s…
6 The Requiem Red £22.… star-… In s…
7 The Dirty Little Secrets of Getting Your Dream Job £33.… star-… In s…
8 The Coming Woman: A Novel Based on the Life of the Infamo… £17.… star-… In s…
9 The Boys in the Boat: Nine Americans and Their Epic Quest… £22.… star-… In s…
10 The Black Maria £52.… star-… In s…
11 Starving Hearts (Triangular Trade Trilogy, #1) £13.… star-… In s…
12 Shakespeare's Sonnets £20.… star-… In s…
13 Set Me Free £17.… star-… In s…
14 Scott Pilgrim's Precious Little Life (Scott Pilgrim #1) £52.… star-… In s…
15 Rip it Up and Start Again £35.… star-… In s…
16 Our Band Could Be Your Life: Scenes from the American Ind… £57.… star-… In s…
17 Olio £23.… star-… In s…
18 Mesaerion: The Best Science Fiction Stories 1800-1849 £37.… star-… In s…
19 Libertarianism for Beginners £51.… star-… In s…
20 It's Only the Himalayas £45.… star-… In s…
# A tibble: 20 × 4
title price rating in_stock
<chr> <dbl> <int> <lgl>
1 A Light in the Attic 51.8 3 TRUE
2 Tipping the Velvet 53.7 1 TRUE
3 Soumission 50.1 1 TRUE
4 Sharp Objects 47.8 4 TRUE
5 Sapiens: A Brief History of Humankind 54.2 5 TRUE
6 The Requiem Red 22.7 1 TRUE
7 The Dirty Little Secrets of Getting Your Dream Job 33.3 4 TRUE
8 The Coming Woman: A Novel Based on the Life of the Inf… 17.9 3 TRUE
9 The Boys in the Boat: Nine Americans and Their Epic Qu… 22.6 4 TRUE
10 The Black Maria 52.2 1 TRUE
11 Starving Hearts (Triangular Trade Trilogy, #1) 14.0 2 TRUE
12 Shakespeare's Sonnets 20.7 4 TRUE
13 Set Me Free 17.5 5 TRUE
14 Scott Pilgrim's Precious Little Life (Scott Pilgrim #1) 52.3 5 TRUE
15 Rip it Up and Start Again 35.0 5 TRUE
16 Our Band Could Be Your Life: Scenes from the American … 57.2 3 TRUE
17 Olio 23.9 1 TRUE
18 Mesaerion: The Best Science Fiction Stories 1800-1849 37.6 1 TRUE
19 Libertarianism for Beginners 51.3 2 TRUE
20 It's Only the Himalayas 45.2 2 TRUE
get_page <-function(i) {nod(session, paste0("catalogue/page-", i, ".html")) |>scrape() |>parse_books() |>mutate(page = i)}books_raw <-map(1:50, get_page) |>list_rbind() # waits 5 s a page
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
dir.create("data", showWarnings =FALSE)write_csv(books_raw, "data/books_raw.csv") # cache the raw pullbooks <-clean_books(books_raw)print(mean(books$price))
[1] 35.07035
books.toscrape Data collected: text permission: terms Method: selector Cleaning rules: NA Known gaps: NA
Checkpoint A.
What is the mean price by rating? The mean price of the books is £34.56
Which line breaks first if the site is redesigned? The parse books function will break as it needs the html tags to remain consistent.
# A tibble: 10 × 4
text author_name author_slug tags
<chr> <chr> <chr> <chr>
1 “The world as we have created it is a process … Albert Ein… Albert-Ein… chan…
2 “It is our choices, Harry, that show what we t… J.K. Rowli… J-K-Rowling abil…
3 “There are only two ways to live your life. On… Albert Ein… Albert-Ein… insp…
4 “The person, be it gentleman or lady, who has … Jane Austen Jane-Austen alit…
5 “Imperfection is beauty, madness is genius and… Marilyn Mo… Marilyn-Mo… be-y…
6 “Try not to become a man of success. Rather be… Albert Ein… Albert-Ein… adul…
7 “It is better to be hated for what you are tha… André Gide Andre-Gide life…
8 “I have not failed. I've just found 10,000 way… Thomas A. … Thomas-A-E… edis…
9 “A woman is like a tea bag; you never know how… Eleanor Ro… Eleanor-Ro… misa…
10 “A day without sunshine is like, you know, nig… Steve Mart… Steve-Mart… humo…
live <-read_html_live("https://quotes.toscrape.com/js/")live |>html_elements(".quote .text") |>html_text2() # ten quotes
[1] "“The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.”"
[2] "“It is our choices, Harry, that show what we truly are, far more than our abilities.”"
[3] "“There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.”"
[4] "“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.”"
[5] "“Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring.”"
[6] "“Try not to become a man of success. Rather become a man of value.”"
[7] "“It is better to be hated for what you are than to be loved for what you are not.”"
[8] "“I have not failed. I've just found 10,000 ways that won't work.”"
[9] "“A woman is like a tea bag; you never know how strong it is until it's in hot water.”"
[10] "“A day without sunshine is like, you know, night.”"
live$view() nrow(quotes)
[1] 100
quotes.toscrape Data collected: text permission: terms Method: selector Cleaning rules: NA Known gaps: NA
Checkpoint B.
nrow(quotes) is 100 from 10 pages. Routes 1 and 2 return the same text for page 1 — which was faster, and which made fewer demands on the server? Which would survive a redesign of the page?
The first routes is much faster and will have made less demands as it does not need to look at the website in a loop. The second option appears to have more resilient to the website changes as it just reads the quotes and text and does not need to unpack the text on the website.