-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscrape.R
More file actions
43 lines (27 loc) · 1.1 KB
/
Copy pathscrape.R
File metadata and controls
43 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
library(tidyverse)
library(stringr)
library(rvest)
library(dobtools)
library(tidytext)
# Safe reading -- don't error if we've got a bad URL, just tell us, don't exit the loop
read_url <- function(url) {
page <- read_html(url)
}
## Our course homepage
# url <- read_url("https://github.com/jennybc/what-they-forgot")
# text <- url %>% html_nodes(".entry-content") %>% html_text()
# View source -> find this url
lobby_url <- read_url("https://gitter.im/what-they-forgot/Lobby/~chat")
text <- lobby_url %>% html_nodes(".js-chat-item-text") %>% html_text()
text_tidied <- text %>% as_tibble() %>%
unnest_tokens(word, value) %>%
anti_join(stop_words) %>% # remove stopwords
filter(! grepl("\\d+", word)) # remove numbers
# Add counts
text_tidied_counts <- text_tidied %>% count(word, sort = TRUE)
text_tidied_counts %>% bind_tf_idf(words, text_tidied_counts, n)
names <- lobby_url %>% html_nodes(".js-chat-item-from") %>% html_text()
library(testthat)
expect_equal(length(names), length(text))
handles <- names %>% str_extract_all("@[a-zA-Z]+") %>% as_vector()
names[which(handles %in% names)]