GET Hackernews Front Page Results using REST API in R

using httr

Whenever we talk about Data Collection, We usually think about Web Scraping. What’s often forgotten is that a lot of websites / web apps usually offer API to access their data in the right way. This video tutorial explains how you can use httr package to use GET requests (REST API Calls) to collected data from Hacker News, a very popular website for Tech News. The objective of this post it that it can outline how to simple use httr’s GET() to start making REST API calls and also to parse the response object and extract desired data.




url <- ""

response <- httr::GET(url)

top500 <- unlist(content(response))

top20 <- top500[1:20]

titles <- c()
scores <- c()
urls <- c()

for(one in top20){
  story_url <- paste0("",one,".json?print=pretty")
  story_response <- httr::GET(story_url)
  titles <- c(titles,content(story_response)$title)
  scores <- c(scores,content(story_response)$score)
  urls <- c(urls,content(story_response)$url)

hn_top20 <-,urls,scores))

Related Posts:

comments powered by Disqus