1

I'm trying to scrape a simple website with Cheerio and Request

Here is my code:

import request from 'request';
request('http://michaelhyatt.com/page/2', function(err, res, html) {
  console.log(html);
});

But the HTML that I get back is gibberish, some kind of weird encoded content:

���r� �lE�?��iSZb�,�DI�<��[k��-yy��v(@H�U������nE��y��y��9;��D����S֗�����M�duϲ�M�
H$�D"3��x����gg?�{����:�z���v�����4��7�c |���&����V��ڇ␌��3⎼�┌["�:��

What am I doing wrong? Other websites I have tried to scrape do not experience this issue.

k.chao.0424
  • 1,191
  • 10
  • 11

1 Answers1

1

I solve the same issue with axios, by just disable encoding on headers by:

            const response = await axios.get(baseUrl, {
                headers: {
                    "Accept-Encoding" : null
                }
            });
            console.log(response)

The answer was found from the comments above from here

Lagamura
  • 59
  • 1
  • 7