GithubHelp home page GithubHelp logo

Wrong encoding detection about rvest HOT 4 CLOSED

tidyverse avatar tidyverse commented on August 22, 2024
Wrong encoding detection

from rvest.

Comments (4)

hadley avatar hadley commented on August 22, 2024

Hmmm, that's a weird one - I can't even figure out what the encoding is supposed to be.

from rvest.

artemklevtsov avatar artemklevtsov commented on August 22, 2024

It's cp1251. I have another example: http://psytests.org/.

from rvest.

hadley avatar hadley commented on August 22, 2024

A few more diagnostics:

library("httr")
library("rvest")
url <- "http://psytests.org"

# No encoding in http request
r <- 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 not
stringi::stri_encode(content(r, "raw"), "ISO-8859-1")

# It's actually cp1251
stringi::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::html
rvest::html("http://psytests.org", encoding = "cp1251")

from rvest.

artemklevtsov avatar artemklevtsov commented on August 22, 2024
rvest::html("http://psytests.org", encoding = "cp1251")

Translates to

rvest:::html.response(httr::GET("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.

from rvest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.