You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
library("httr")
library("rvest")
url<-"http://psytests.org"# No encoding in http requestr<- GET(url)
headers(r)$`Content-Type`# So default text content from httr is bad
content(r, "text")
# stringi thinks encoding is ISO-8859-1
as.data.frame(stringi::stri_enc_detect(content(r, "raw"))[[1]])
# But it's notstringi::stri_encode(content(r, "raw"), "ISO-8859-1")
# It's actually cp1251stringi::stri_encode(content(r, "raw"), "cp1251")
# Which also works when we give it to content
content(r, "text", encoding="cp1251")
# But not when we give it to rvest::htmlrvest::html("http://psytests.org", encoding="cp1251")
In rvest:::html.response we can see that text <- httr::content(x, "text") called without encoding arg. Then XML::htmlParse applied on the broken string.
Activity
hadley commentedon Nov 24, 2014
Hmmm, that's a weird one - I can't even figure out what the encoding is supposed to be.
artemklevtsov commentedon Nov 24, 2014
It's
cp1251. I have another example: http://psytests.org/.hadley commentedon Nov 25, 2014
A few more diagnostics:
artemklevtsov commentedon Nov 26, 2014
Translates to
In
rvest:::html.responsewe can see thattext <- httr::content(x, "text")called withoutencodingarg. ThenXML::htmlParseapplied on the broken string.