R/get_num_results-internal.R

Defines functions get_num_results

Documented in get_num_results

#' get_num_results
#'
#' @description Find out how many results are available for the search
#'
#' @param query The URL specifying the query
#'
#' @return
#'
#' @import magrittr
#' @keywords internal
#' @export
#'
get_num_results <- function(query)
{
  ## The raw query
  raw_query <- xml2::read_html(query)

  ## Get the total result count and convert to numeric
  tot_results <- raw_query %>%
    rvest::html_nodes("span.totalcount") %>%
    extract(1) %>%
    rvest::html_text() %>%
    as.numeric()

  return(tot_results)
}
adletaw/craigr documentation built on Feb. 21, 2020, 10:14 p.m.