Four Exercises to Practice Our Web-Scraping and API-Calls

SICSS-Oxford

Tuesday 15-06-2021

Question 1A. (Basic): Scrape and print out a quote from the Simpsons API.

Question 1B. (Advanced): How many quotes are on the API?

Question 2A. (Basic): Scrape a picture of a cat from thecatapi and programatically show it in an ipynb or rmd file.

2.b. (Advanced): Can you download a hundred of these pictures and turn them into a .gif?

Question 3.a (Basic): Search Twitter for the last two year of cbarries tweets.

from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage as STAP import rpy2 rpy2.robjects.r'options'

string = """ library(academictwitteR) bearer_token <- ""

users <- c("cbarrie") tweets_df <- get_user_tweets(users, "2016-06-13T00:00:00Z", "2021-06-13T00:00:00Z", bearer_token)

write.csv(tweets_df$text, 'tweets_cbarrie.csv') """

STAP(string, "r_func")

Q3.a. Cont: How many times has he mentioned SICSS?

Question 3.b (Advanced): What hashtags does @cbarrie spam the most?

Question 4.a (Basic): Can you scrape thepeerage...?

4.a (cont): and parse the biography of Prince Charles?\

Question 4.b (Advanced): What perecent of people on the first ten pages are males, and how many are females?