Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs sync-request not returning HTML Response

const cheerio = require('cheerio');
const request = require('sync-request');
const fs = require('fs');


var res = request('GET', 'https://edition.cnn.com/');
console.log(res.getBody())

This is my code. I want to get HTML code of https://edition.cnn.com/. But it returning following:

<Buffer 3c 21 44 4f 43 54 59 50 45 20 68 74 6d 6c 3e 3c 68 74 6d 6c 20 63 6c 61 73 73 3d 22 6e 6f 2d 6a 73 22 3e 3c 68 65 61 64 3e 3c 6d 65 74 61 20 63 6f 6e ... >
like image 840
Watermelon Avatar asked Sep 07 '25 13:09

Watermelon


1 Answers

You are receiving a buffer currently, you need to convert it to string. Use this -

console.log(res.getBody().toString())

like image 148
Kamesh Avatar answered Sep 09 '25 14:09

Kamesh