R/w3cValidate.R

Defines functions w3cValidate

Documented in w3cValidate

#' Function to preform a W3C Validation Test for a specific URL
#'
#' This function allows you to perform a W3C Validation test for a given URL. You will get the number of Errors and Warnings for the URL as Data Frame.
#' @param url The url you want to perform the Validation for
#' w3cValidate()
#' @examples
#' w3cValidate("https://www.r-project.org/")

w3cValidate <- function(url) {
  w3c <-
    xml2::read_html(paste0(
      "https://validator.w3.org/nu/?doc=",
      URLencode(url),
      "&out=json"
    ))
  #Count the errors in the document
  error_count <-
    as.data.frame(stringr::str_count(w3c, '.error...lastLine.'))
  warning_count <- as.data.frame(stringr::str_count(w3c, 'warning'))
  w3c <- cbind(error_count, warning_count)
  colnames(w3c) <- c("Errors", "Warnings")
  return(w3c)
}

Try the seoR package in your browser

Any scripts or data that you put into this service are public.

seoR documentation built on Jan. 29, 2018, 5:05 p.m.