-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added www.telegraph.co.uk and us.cnn.com scraper (#1)
- Loading branch information
Showing
5 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: paperboy | ||
Title: Comprehensive collection of news media scrapers | ||
Version: 0.0.1.9000 | ||
Date: 2021-09-02 | ||
Date: 2021-09-03 | ||
Authors@R: person("Johannes", "Gruber", email = "[email protected]", | ||
role = c("aut", "cre")) | ||
Description: A comprehensive collection of webscraping scripts for news media sites. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
pb_deliver_paper.www_telegraph_co_uk <- function(x, verbose = NULL, ...) { | ||
|
||
. <- NULL | ||
|
||
if (is.null(verbose)) verbose <- getOption("paperboy_verbose") | ||
|
||
if (!"tbl_df" %in% class(x)) | ||
stop("Wrong object passed to internal deliver function: ", class(x)) | ||
|
||
if (verbose) message("\t...", nrow(x), " articles from ", x$domain[1]) | ||
|
||
pb <- make_pb(x) | ||
|
||
purrr::map_df(x$content_raw, function(cont) { | ||
|
||
if (verbose) pb$tick() | ||
html <- rvest::read_html(cont) | ||
|
||
# datetime | ||
datetime <- html %>% | ||
rvest::html_element("[itemprop=\"datePublished\"]") %>% | ||
{ | ||
out <- rvest::html_attr(., "content") | ||
if (is.na(out)) { | ||
out <- rvest::html_attr(., "datetime") | ||
} | ||
out | ||
} %>% | ||
as.POSIXct(format = "%Y-%m-%dT%H:%M%z") | ||
|
||
# headline | ||
headline <- html %>% | ||
rvest::html_elements("[property=\"og:title\"]") %>% | ||
rvest::html_attr("content") | ||
|
||
# author | ||
author <- html %>% | ||
rvest::html_elements("[class*=\"byline__author\"]") %>% | ||
rvest::html_attr("content") %>% | ||
toString() %>% | ||
gsub("^By\\s", "", .) | ||
|
||
# text | ||
text <- html %>% | ||
rvest::html_elements("[class*=\"article-body-text\"]") %>% | ||
rvest::html_text2() %>% | ||
paste(collapse = "\n") | ||
|
||
# type | ||
content_type <- html %>% | ||
rvest::html_element("[property=\"og:type\"]") %>% | ||
rvest::html_attr("content") | ||
|
||
tibble::tibble( | ||
datetime, | ||
author, | ||
headline, | ||
text, | ||
content_type | ||
) | ||
}) %>% | ||
cbind(x) %>% | ||
normalise_df() %>% | ||
return() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters