Skip to content

Commit

Permalink
fix: use rvest::read_html instead of httr::content on formatted link
Browse files Browse the repository at this point in the history
  • Loading branch information
tin900 committed Aug 5, 2024
1 parent 9355c92 commit 64223af
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions R/google_translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ google_translate <- function(text, target_language = "en", source_language = "au
)

if (is_vector) {
responses <- purrr::map(formatted_link, httr::GET)

translations <- purrr::map(responses, ~ {
translation <- httr::content(.x) %>%
translations <- purrr::map(formatted_link, ~ {
translation <- rvest::read_html(.x) %>%
rvest::html_nodes("div.result-container") %>%
rvest::html_text()

Expand All @@ -53,9 +51,7 @@ google_translate <- function(text, target_language = "en", source_language = "au

return(translations)
} else {
response <- httr::GET(formatted_link)

translation <- httr::content(response) %>%
translation <- rvest::read_html(formatted_link) %>%
rvest::html_nodes("div.result-container") %>%
rvest::html_text()

Expand Down

0 comments on commit 64223af

Please sign in to comment.