GithubHelp home page GithubHelp logo

Comments (3)

JCMais avatar JCMais commented on July 22, 2024 1

The Curl wrapper module always use UTF-8 for decoding purposes. If you need to use something different you must disable the parsing of the data or don't use the wrapper at all, and instead use the Easy constructor.

var Curl = require( 'node-libcurl' ).Curl,
    // a package to convert from given encoding,
    //  we are using iconv-lite here (https://github.com/ashtuchkin/iconv-lite)
    iconv = require( 'iconv-lite' ),
    curl = new Curl();

curl.setOpt( Curl.option.URL, 'http://www1.bloomingdales.com/shop/product/mac-powder-blush-wash-dry-collection?ID=1371879' );
curl.setOpt( Curl.option.FOLLOWLOCATION, true );
curl.setOpt( Curl.option.COOKIEJAR, "cookie.jar" )
curl.setOpt( Curl.option.COOKIEFILE, "cookie.jar" )

// Enable the NO_DATA_PARSING bitmask, this basically means that
// the data will be returned to the end callback without any conversion.
curl.enable( Curl.feature.NO_DATA_PARSING );

function errorCallback( error, errCode ) {

    console.log( error, errCode );
    this.close();
}

function endCallback( statusCode, body, headers ) {

    // Since we enabled NO_DATA_PARSING, body will be a Buffer object here, and not a string.
    // parse it using the decoder
    console.log( iconv.decode( body, 'ISO-8859-1' ).substring( 0, 2000 ) );
    this.close();
}

curl.on( 'error', errorCallback );
curl.on( 'end', endCallback );
curl.perform();

from node-libcurl.

JCMais avatar JCMais commented on July 22, 2024

Btw if you wanted to convert this automatically by getting the charset in the header, it would not work for the given link, since the server there is sending the wrong charset in the headers. It's using utf-8 on the header but ISO-8859-1 in the body.

from node-libcurl.

TariqAbughofa avatar TariqAbughofa commented on July 22, 2024

Nice, I didn't know that you can stop data parsing.
yeah, I know many websites mess up the charset in the headers and the html. that's why I understand that the library should not depend on that to detect the encoding.
thanks a lot.

from node-libcurl.

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.