Skip to content

Instantly share code, notes, and snippets.

@aleszu
Created August 26, 2020 11:45
Show Gist options
  • Save aleszu/84f5671781debe1c554fc33554b31f6e to your computer and use it in GitHub Desktop.
Save aleszu/84f5671781debe1c554fc33554b31f6e to your computer and use it in GitHub Desktop.
library(rvest)
library(tidyRSS)
library(tidyverse)
library(stringr)
# https://www.cjr.org/analysis/as-election-looms-a-network-of-mysterious-pink-slime-local-news-outlets-nearly-triples-in-size.php
pinkslimesites <- read.csv("pinkslimesites.csv", stringsAsFactors = F)
all_pinkslimesites <- pinkslimesites %>%
mutate(Rss = paste0(Domain,"/stories.rss"))
all_RSS_urls <- all_pinkslimesites$Rss
RSS_function <- function(all_RSS_urls) {
stories <- tidyfeed(all_RSS_urls,
config = list(), clean_tags = TRUE,
list = FALSE, parse_dates = TRUE )
}
# run with safely() to store error mssgs
safe_scrape <- safely(RSS_function)
# Pull in RSS feed for last 20 articles!
all_titles <- map(all_RSS_urls, safe_scrape)
glimpse(all_titles)
all_titles_mapped <- all_titles %>% # Put the result from RSS feed into a dataframe
map_df(~ .x[["result"]])
glimpse(all_titles_mapped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment