Site icon R-bloggers

Monitoring Price Fluctuations of Book Trade-In Values on Amazon

[This article was first published on Category: R | Statistically Significant, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I am planning to finish school soon and I would like to shed some weight before moving on. I have collected a fair number of books that I will likely never use again and it would be nice to get some money for them. Sites like Amazon and eBay let you sell your book to other customers, but Amazon will also buy some of your books directly (Trade-Ins), saving you the hassle of waiting for a buyer.

Before selling, I remembered listening to a Planet Money episode about a couple of guys that tried to make money off of buying and selling used textbooks on Amazon. Their strategy was to buy books at the end of a semester when students are itching to get rid of them, and sell them to other students at the beginning of the next semester. To back up their business, they have been scraping Amazon’s website for years, keeping track of prices in order to find the optimal times to buy and sell.

I collected a few books I was willing to part with and set up a scraper in R. I am primarily interested in selling my books to Amazon, so I tracked Amazon’s Trade-In prices for these books. This was done fairly easily with Hadley Wickham’s package rvest and the Chrome extension Selector Gadget. Selector Gadget tells me that the node I’m interested in is #tradeInButton_tradeInValue. The code to do the scraping is below.

< notextile>
Amazon_scrape_prices.Rlink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(rvest)</p>

<p>urls_df = read.csv(&ldquo;AmazonBookURLs.csv&rdquo;, stringsAsFactors = FALSE, comment.char = &ldquo;&rdquo;)
load(file = &ldquo;AmazonBookPrices.RData&rdquo;)
price_df_temp = data.frame(Title = urls_df$Title,
                      Date = Sys.time(),
                      Price = NA_real_, stringsAsFactors = FALSE)
for (i in 1:nrow(urls_df)) {
  tradein_html = urls_df$URL[i] %&gt;% html() %&gt;%
    html_node(&ldquo;#tradeInButton_tradeInValue&rdquo;)
  if (is.null(tradein_html)) {
    next
  }
  price = tradein_html %&gt;%
    html_text() %&gt;%
    gsub(&ldquo;(^[[:space:]]+$|[[:space:]]+$)&rdquo;, &ldquo;&rdquo;, .) %&gt;%
    as.numeric()
  price_df_temp$Price[i] = price
}
price_df = rbind(price_df, price_df_temp)</p>

<p>save(price_df, file = &ldquo;AmazonBookPrices.RData&rdquo;)

After manually collecting this data for less than a week, I am able to plot the trends for the eight books I am interested in selling. The plot and code are below.

< notextile>
plot_amazon_prices.Rlink
1
2
3
4
5
6
7
library(ggplot2); theme_set(theme_bw())
library(scales)</p>

<p>price_df$TitleTrunc = paste0(substring(price_df$TitleTrunc, 1, 30), ifelse(nchar(price_df$Title) &gt; 30, &ldquo;&hellip;&rdquo;, &ldquo;&rdquo;))
ggplot(price_df, aes(Date, Price)) +
  geom_step() + geom_point() + facet_wrap(~ TitleTrunc, scales = &ldquo;free_y&rdquo;) +
  scale_y_continuous(labels = dollar) + theme(axis.text.x = element_text(angle = 90, vjust = 0))

I am surprised how much the prices fluctuate. I expected them to be constant for the most part, with large changes once a week or less often. Apparently Amazon is doing quite a bit of tweaking to determine optimal price points. I would also guess that $2 is their minimum trade-in price. It looks like I missed out on my best chance to sell A First Course in Stochastic Processes, but that the price of A Primer on Linear Models will keep rising forever.

To leave a comment for the author, please follow the link and comment on their blog: Category: R | Statistically Significant.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.