Skip to content

Instantly share code, notes, and snippets.

@johnbaums
Created February 3, 2020 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbaums/b97600adfc87e668eeda23be9c7949bf to your computer and use it in GitHub Desktop.
Save johnbaums/b97600adfc87e668eeda23be9c7949bf to your computer and use it in GitHub Desktop.
Get all listed coauthors for a given Google Scholar profile
gs_coauthors <- function(id) {
# id: a Google Scholar author ID.
# ^ e.g., for url https://scholar.google.com/citations?user=RWh6yJcAAAAJ&hl=en,
# the ID is 'RWh6yJcAAAAJ').
require(xml2)
require(rvest)
require(dplyr)
paste0('https://scholar.google.com.au/citations?view_op=list_colleagues&hl=en&json=&user=', id) %>%
xml2::read_html() %>%
rvest::html_nodes(., '.gs_ai_t') %>%
list(author=rvest::html_nodes(., 'h3 > a') %>% rvest::html_text(),
id=rvest::html_nodes(., 'h3 > a') %>% rvest::html_attr('href'),
affil=rvest::html_nodes(., '.gs_ai_aff') %>% rvest::html_text(),
domain=rvest::html_nodes(., '.gs_ai_eml') %>% rvest::html_text()) %>%
.[-1] %>%
as.data.frame(stringsAsFactors=FALSE) %>%
dplyr::as.tbl() %>%
dplyr::mutate(domain=sub('Verified email at ', '', domain),
domain=sub('.*\\.', '', domain),
id=sub('.*=', '', id),
surname=tolower(sub('.* ', '', author)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment