Tools to Work with the 'Splash' JavaScript Rendering Service in R
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

40 行
1.1KB

  1. #' Return a HAR entry response as an httr::response object
  2. #'
  3. #' @param har_entry a HAR object (should contain a response body to be most useful)
  4. #' @export
  5. #' @examples \dontrun{
  6. #' library(purrr)
  7. #'
  8. #' URL <- "http://www.svs.cl/portal/principal/605/w3-propertyvalue-18554.html"
  9. #'
  10. #' splash_local %>%
  11. #' splash_response_body(TRUE) %>%
  12. #' splash_user_agent(ua_macos_chrome) %>%
  13. #' splash_go(URL) %>%
  14. #' splash_wait(2) %>%
  15. #' splash_har() -> har
  16. #'
  17. #' keep(har$log$entries, is_xhr) %>%
  18. #' map(as_request) %>%
  19. #' map(httr::content, as="parsed")
  20. #' }
  21. as_response <- function(har_entry) {
  22. if (length(har_entry$response$content$text) > 0) {
  23. content_body <- openssl::base64_decode(har_entry$response$content$text)
  24. } else {
  25. content_body <- NULL
  26. }
  27. structure(list(
  28. url = har_entry$request$url,
  29. status_code = har_entry$response$status,
  30. date = lubridate::ymd_hms(har_entry$startedDateTime),
  31. headers = setNames(map(har_entry$response$headers, "value"),
  32. map(har_entry$response$headers, "name")) %>%
  33. insensitive(),
  34. content = content_body
  35. ), class="response")
  36. }